# new FluxState(config)
Parameters:
Name | Type | Description |
---|---|---|
config |
Object
|
The configuration object |
id |
string
|
The ID to use for the FluxState; should be unique among all other active Flux objects |
value |
*
|
The initial value to set as data; this will be recursively cloned so that any changes to
this value (if it is an object) will not affect the |
Methods
# get() → {*}
Gets a deeply-cloned copy of the current data from the FluxState.
A deeply-cloned copy of the current data from the FluxState.
*
Example
// Create a FluxState object
const profileState = createFluxState({
id: 'profileState',
value: { name: 'John' },
});
// Read the FluxState object's current value
const profile = profileState.get(); // { name: 'John' }
# set(newValue)
Sets the new value for the FluxState.
Parameters:
Name | Type | Description |
---|---|---|
newValue |
*
|
The new value to store in the FluxState |
Example
// Create a FluxState object
const profileState = createFluxState({
id: 'profileState',
value: null,
});
// Set the FluxState object's new value
profileState.set({ name: 'John' });
// The FluxState will now hold the new value
const profile = profileState.get(); // { name: 'John' }