Skip to content

Commit

Permalink
# parent 7a9fb69
Browse files Browse the repository at this point in the history
# author Douglas Armstrong <dougarmstrong@fb.com> 1593194584 -0700
# committer eLeontev <joonior199@gmail.com> 1594193309 +0300

# This is a combination of 4 commits.
# This is the 1st commit message:

# [docs] Clarify <RecoilRoot> initializeState (facebookexperimental#411)

# [docs] Add extra unstable note

# [docs] minor blog formatting

# [docs] Clarify <RecoilRoot> initializeState
# This is the commit message facebookexperimental#2:

# Fix word spelling errors (facebookexperimental#419)

# Fix word spelling errors

# Fix grammatical errors

# Fix formatting
# This is the commit message facebookexperimental#3:

# fix: initializeState example type (facebookexperimental#426)

# fix: initializeState example type

# docs: remove spaces around destructuring
# This is the commit message facebookexperimental#4:

Update useResetRecoilState.md description to missed part about re-rendering

# Update useResetRecoilState.md

# fix description to proposed message

# revert wrong replaced single quotes to double
  • Loading branch information
drarmstr authored and eLeontev committed Jul 8, 2020
1 parent 7a9fb69 commit 6c6c0b3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions docs/blog/2020-06-18-0.0.10-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ The `<RecoilRoot>` component also has an `initializeState` prop which can be use
function MyApp() {
return (
<RecoilRoot
initializeState(({set}) => {
initializeState={({set}) => {
for (const [atom, value] of atoms) {
set(atom, value);
}
}>
}}
>
<AppContents />
</RecoilRoot>
);
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api-reference/core/RecoilRoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Provides the context in which atoms have values. Must be an ancestor of any comp

**Props**:
- `initializeState?`: `(MutableSnapshot => void)`
- An optional function that takes a [`MutableSnapshot`](/docs/api-reference/core/Snapshot#Transforming_Snapshots) to initialize the global state.
- An optional function that takes a [`MutableSnapshot`](/docs/api-reference/core/Snapshot#transforming-snapshots) to initialize the `<RecoilRoot>` atom state. This sets up the state for the initial render and is not intended for subsequent state changes or async initialization. Use hooks such as [`useSetRecoilState()`](/docs/api-reference/core/useSetRecoilState) or [`useRecoilCallback()`](/docs/api-reference/core/useRecoilCallback) for async state changes.


### Example
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/api-reference/core/useResetRecoilState.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ sidebar_label: useResetRecoilState()

Returns a function that will reset the value of the given state to its default value.

Using **useResetRecoilState()** allows a component to reset the state to its default value without subscribing to re-render whenever the state changes.

---

```jsx
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/guides/persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Note that the current hook was designed for persistence and only reports atoms w

## Restoring State

After you ensure that you're saving your state to your storage, you need to recover it when loading the app. This can be done using the **`initializeState`** prop on thee **`<RecoilRoot>`** component. (***NOTE***: *API changes coming soon*).
After you ensure that you're saving your state to your storage, you need to recover it when loading the app. This can be done using the **`initializeState`** prop on the **`<RecoilRoot>`** component. (***NOTE***: *API changes coming soon*).

`initializeState` is a function that provides a **`set`** method to provide the initial atom value for an atom key.
Pass the key for the atom and the stored value to this callback and it will initialize the atom to the restored state.
Expand All @@ -54,7 +54,7 @@ Here is a basic example:
```jsx
const initializeState = ({set}) => {
for(const [key, value] of Storage.entries()) {
set(getAtomWithKey(key), JSON.parse(value)).value;
set(getAtomWithKey(key), JSON.parse(value).value);
}
}

Expand All @@ -74,4 +74,4 @@ You may also wish for asynchronous updates of the storage, such as the user pres

## Backward-Compatibility and Value Validation

What if your state storage is not reliable? Or what if you change which atoms or types you are using and need to work with previously persisted state? More documentation and examples on how to handle this coming soon as the API is finalized...
What if your state storage is not reliable? Or what if you change which atoms or types you are using and need to work with previously persisted state? More documentation and examples on how to handle this coming soon as the API is finalized...

0 comments on commit 6c6c0b3

Please sign in to comment.