Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Mar 2, 2024
1 parent 4f9d887 commit aa5c4c9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
5 changes: 4 additions & 1 deletion website/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ const Component = () => {

## memo

`memo` is removed in v2. With v2, we can use `React.memo`.
The description below only applies to v1.

There is a utility function exported from the library.

This should be used instead of `React.memo` if props
Expand All @@ -155,7 +158,7 @@ work correctly because a memoized component doesn't always render
when a parent component renders.

```javascript
import { memo } from 'react-tracked';
import { memo } from 'react-tracked'; // v1 only

const ChildComponent = memo(({ num1, str1, obj1, obj2 }) => {
// ...
Expand Down
4 changes: 3 additions & 1 deletion website/docs/caveats.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const state2 = useTrackedState();
You should use `useTrackedState` only once in a component
if you need referential equality of objects in the state.

## An object referential change doesn't trigger re-render if an property of the object is accessed in previous render
## An object referential change doesn't trigger re-render if an property of the object is accessed in previous render (v1 only)

:warning: This caveat only applies to v1. Since v2, we don't have such limitations.

```javascript
const state = useTrackedState();
Expand Down
7 changes: 2 additions & 5 deletions website/docs/tutorial-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,8 @@ export default React.memo(TodoItem);
```

This is the TodoItem component.
We prefer primitive props for memoized components.

If you want to use object props for memoized components,
you need to use a special [memo](../api#memo) instead of `React.memo`.
See [example/09](https://github.com/dai-shi/react-tracked/tree/main/examples/09_reactmemo) for the usage.
We used to prefer primitive props for memoized components with v1.
With v2, object props are also fine.

## src/NewTodo.js

Expand Down
7 changes: 2 additions & 5 deletions website/docs/tutorial-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,8 @@ export default React.memo(TodoItem);
```

This is the TodoItem component.
We prefer primitive props for memoized components.

If you want to use object props for memoized components,
you need to use a special [memo](../api#memo) instead of `React.memo`.
See [example/09](https://github.com/dai-shi/react-tracked/tree/main/examples/09_reactmemo) for the usage.
We used to prefer primitive props for memoized components with v1.
With v2, object props are also fine.

## src/components/NewTodo.js

Expand Down

0 comments on commit aa5c4c9

Please sign in to comment.