GitHub

Core Concepts

The Manifest

The Manifest is where Radonis stores all its data. It is accessible both client-side and server-side, which makes hydration possible.


Extending the Manifest

You can add custom data to the Manifest, for example the currently logged in user or some global application settings. To extend the Manifest, first add the types for your custom data to contracts/radonis.ts inside of the Globals interface. Then, call withGlobals in your controllers, routes, middlewares or everywhere radonis is available on the HttpContext.

// app/Controllers/Http/UsersController.ts
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import { Index, Show } from '../../../resources/views/Users.tsx'


export default class UsersController {
  public index({ radonis }: HttpContextContract) {
    return radonis.withGlobals({ user: { id: 1, email: 'radonis@example.com' } }).render(Index)
  }
}

You can optionally pass globals directly to the render call as the third argument.

// start/routes.ts
import Route from '@ioc:Adonis/Core/Route'
import { SignUp } from '../resources/views/Auth.tsx'


Route.get('/signUp', async ({ radonis }) => {
  return radonis.render(SignUp, undefined, {
    globals: { user: { id: 1, email: 'radonis@example.com' } },
  })
})

Then, retrieve your custom data with the useGlobals hook.

import { useGlobals } from '@microeinhundert/radonis'


const globals = useGlobals()


console.log(globals) // => `{ user: { id: 1, email: 'radonis@example.com' } }`

Note

Call withGlobals in a custom middleware to make globals available to all routes in your application.


Data availability

By default, Radonis limits the client-side Manifest to only include data required for hydration. However, if your specific use case requires having the same Manifest both client-side and server-side, set client.limitManifest to false in the Radonis config.

Previous
Components and Islands