Isomorphic Hooks
useFlashMessages
Retrieve session flash messages available for the current HTTP request.
Client / Server
Usage
Retrieve all flash messages.
import { useFlashMessages } from '@microeinhundert/radonis'
const flashMessages = useFlashMessages()
console.log(flashMessages.all()) // => `{ 'helloWorld': 'hello world', ... }`
Check if any flash message exists.
import { useFlashMessages } from '@microeinhundert/radonis'
const flashMessages = useFlashMessages()
console.log(flashMessages.hasAny()) // => `true` or `false`
Check if some specific flash message exists.
import { useFlashMessages } from '@microeinhundert/radonis'
const flashMessages = useFlashMessages()
console.log(flashMessages.has$('helloWorld')) // => `true` or `false`
Retrieve some specific flash message.
import { useFlashMessages } from '@microeinhundert/radonis'
const flashMessages = useFlashMessages()
console.log(flashMessages.get$('helloWorld')) // => `hello world`
Flash message arrays
Flash messages can be grouped to specific namespaces. For example, errors.fieldName
points to the key fieldName
nested inside the object with key errors
. The value can also be an array of messages, in which case items can be accessed by appending the index like so: errors.fieldName.0
.
Tip
Omitting the index will automatically get the first flash message in an array of flash messages. For example: errors.fieldName
is the same as errors.fieldName.0
.