Skip to content

Initial atom state  #119

@istarkov

Description

@istarkov

Currently the most issue I see with atoms is initial atom state which especially on server cant be inside any global objects ie localStorage etc. (setEffect is not working on server too)

Creating atoms and passing them through a context - loss of main advantages (u would need to create dependent atoms in context etc)

Probably passing Provider value to atom on initial call could solve this?

I.e.

// atom already have getter fn as param so I call atom with state dependent on context subatom.

const myAtom = subatom(ctx => ctx.someVal)

....
// in some component

<InitialJotaiValueProvider value={{ someVal: 123 }}> ...

Or probably some other beautiful api can be available.

PS: Api like above can be typed well like

const { InitialValueProvider, subatom} = createBlaBla<ValueType>()

Metadata

Metadata

Assignees

No one assigned

    Labels

    has snippetThis issue includes code snipppets as solutions or workarounds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions