Skip to content

How to implement the init$ function #208

Answered by lazarv
kooooo1tktn asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @kooooo1tktn!

To make init$ work, you need to export it from your entry module. Based on your description, you use the built-in file-system based router, which supports middleware files instead of the init$ function.

The init$ function only works when using @lazarv/react-server directly with a React Server Component entry, like react-server ./App.jsx and the App.jsx file exports an init$ function.

You don't need to add a "use server" directive in middlewares or the entry module, as this directive exposes all exported functions from a module to be consumable as server functions, which are callable by a client.

You can use any HTTP context helpers the framework provides inside a middlewa…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kooooo1tktn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants