Skip to content

Using nested store #85

Answered by Brentlok
gabimoncha asked this question in Q&A
Oct 30, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hello @gabimoncha! 😊 Thank you for starting this interesting topic!

immer is a pure JavaScript library, so feel free to use it with stan-js, since "integration" is already here 😅. Here's some example code to illustrate:

type EntryPayload = {
    value: number
    details: string
}

const { useStore, actions } = createStore({
    entries: {
        '2024': {
            '2024-10-29': {
                value: 10,
                details: 'Had a great run',
            },
        },
    } as Record<string, Record<string, EntryPayload>>,
})

const updateEntry = (year: string, date: string, payload: EntryPayload) => {
    actions.setEntries(produce(draft => {
        draft[year][date] = payload

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@chertik77
Comment options

@Brentlok
Comment options

Answer selected by Brentlok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants