JS Shared Data
This package provides a front-end solution for the coderello/laravel-shared-data
package.
Install
yarn add js-shared-data
Usage
Let's imagine that we shared such data from the backend using coderello/laravel-shared-data
:
share([
'user' => [
'full_name' => 'Ilya Sakovich',
'username' => 'hivokas',
'email' => 'me@hivokas.com',
],
'balance' => 120,
]);
On the front-end side we can access this data using shared()
helper.
import { shared } from 'js-shared-data';
const user = shared('user');
const username = shared('user.username');
const balance = shared('balance');
const status = shared('status', 'Working...');
Customization
import { sharedData } from 'js-shared-data';
sharedData.setDefaultValue(null);
sharedData.setNamespace('App');
sharedData.setSource(window);