ApiProvider
Code
// server/render.js (based on Express framework)
import React from 'react'
import ReactDom from 'react-dom'
import axios from 'axios'
import { ApiProvider, injectSSRHtml } from 'react-use-api'
import App from '../../src/App'
export const render = async (req) => {
const apiContext = {
settings: {
axios, // your custom axios instance
isSSR: () => true // we are 100% sure here is SSR mode
}
}
const renderSSR = () =>
ReactDom.renderToString(
<ApiProvider context={apiContext}>
<App />
</ApiProvider>
)
const html = await injectSSRHtml(apiContext, renderSSR)
return html
}Settings (ReactUseApi.CustomSettings) Options
Last updated
Was this helpful?