
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
@blackblock/render-to-string-with-data
Advanced tools
A hook for the free and the brave to implement data hydration in SSR and SSG in React.
A hook for the free and the brave to implement data hydration in SSR and SSG in React.
If you need to have data hydration in SSR and SSG, but you don't want to develop in a heavily opinionated framework, namely Next.js, Gatsby or React Static, this hook is for you.
Data hydration for SSR and SSG using useContext()
Isolating server data and client data for hydration(You can also hydrate with the same data if you wish)
Cache data response in server for performance benefit and development convenience
No Redux
//In your component where you want to hydrate server side
import {
useServerSideEffect
} from '@blackblock/render-to-string-with-data'
function App(){
const openSourceData = useServerSideEffect({
callback: () => {
return fetch("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread")
.then(response => response.json())
.catch(e => console.log(e))
},
key: 'github', //Unique key for storing data of this request
clientSideState: {} //initial value for client side
cacheDuration: 2592000
})
return (
<p>
{openSourceData.warningMessage}
</p>
)
}
//Then in file where you do SSR or SSG:
import {
renderToStringWithData
} from '@blackblock/render-to-string-with-data/server'
const renderApp = async () => {
//data is the request data. You can write them to file system as JSON if you need.
const { data, markupWithData } = await renderToStringWithData(<App />)
}
With Npm:
npm install @blackblock/render-to-string-with-data
With Yarn:
yarn add @blackblock/render-to-string-with-data
react and react-dom should be installed in your application, as they are the peer dependencies of this package.
<ServerSideEffectProvider>The followings are the options you can pass to <ServerSideEffectProvider>.
valuevalue::Object
You need to pass an object in the following structure:
const context = {
sse: {
}
}
//then pass this context in renderToString or in place where you use <ServerSideEffectProvider>
renderToString(
<ServerSideEffectProvider value={context}>
<App />
</ServerSideEffectProvider>
)
renderToStringWithDataThe followings are the options you can pass to renderToStringWithData.
markupYour React application. Do not pass in an application with <ServerSideEffectProvider> in it, as renderToStringWithData internally does that for you.
useServerSideEffectThe followings are the options you can pass to useServerSideEffect.
callbackcallback::Function
A server side callback to run like useEffect
keykey::String
Key for mutating the context object
clientSideStateclientSideState::Any
The state to take over in client side. It should be treated as initial state.
cacheDurationcacheDuration::Int | Boolean
cacheDuration is default to false
The duration (in ms) which the promise returned from your callback would be replaced by data cached previously in your file system.
If you set it to false, cache would be disabled for that hook. Setting it to true will always read from the cache.
FAQs
A hook for the free and the brave to implement data hydration in SSR and SSG in React.
The npm package @blackblock/render-to-string-with-data receives a total of 0 weekly downloads. As such, @blackblock/render-to-string-with-data popularity was classified as not popular.
We found that @blackblock/render-to-string-with-data demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.