neuron
Home / core / Read and Update State
Reading and updating state in Neuron is very easy. You must call the methods below to perform each task.
Calling the getRef
method will return the current value of the state. This is a reference of the state.
const name = new Neuron("Ash Ketchum");
name.getRef(); //Ash Ketchum
To update state you must call the set
method.
name.set("Gary Oak");
name.getRef(); //Gary Oak
The set
method can also take a predicate to grab the previous state value. Example below.
name.set((prev) => `${prev} is lame.`);
name.getRef(); //Gary Oak is lame.