Update state based on existing state? #88
|
Hello, Is there a way to update the state based on the existing state? For example: import { Persistent } from "narraleaf-react";
type State = {
mood: number;
};
const state = new Persistent<State>("state", {
mood: 10,
});
// Player does something that decreases mood by 1
state.set("mood", state.get("mood") - 1),Thank you! |
Answered by
helloyork
Sep 5, 2025
Replies: 1 comment 1 reply
|
Yes, please refer to set<K extends StringKeyOf> The second overload allows you to pass in a function to update the data based on the previous state. state.set("mood", (mood) => mood - 1), |
1 reply
Answer selected by
fsharpn00b
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, please refer to set<K extends StringKeyOf>
The second overload allows you to pass in a function to update the data based on the previous state.