Avoiding computation of initial values on store creation #717
Replies: 2 comments 1 reply
-
Is it specific to One thing I can think of is to initialize with export const useStore = create(set => ({
uuid: null,
}));
const initializeStore = () => {
useStore.setStore({
uuid: crypto.randomUUID(),
})
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
It's kind of specific to More generally, I think |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a persisted store with a variable whose initial value is the result of a function:
By the nature of JavaScript,
crypto.randomUUID()
is called every time this code runs. Is it possible to avoid such useless and expensive computations during store initialization?I thought about doing
() => crypto.randomUUID()
but I think such a function variable won't work as expected.Beta Was this translation helpful? Give feedback.
All reactions