Read and Update State

Reading and updating state in Neuron is very easy. You must call the methods below to perform each task.

Read state

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

Update state

To update state you must call the set method.

name.set("Gary Oak");
name.getRef(); //Gary Oak

Setting with the previous state selector

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.

Find Me On

© Copyright David A. Sanders 2025