[React] Choose the Right Hook for Your Recoil State

Recoil offers several hooks to use for consuming state in React, and this lesson looks at how to choose which hook to use, and what happens when you don't use the right hook (hint: extra renders).

The three basic RecoilJS hooks are:

  1. useRecoilState, which is great for reading and writing state,
  2. useRecoilValue, ideal for reading state, and
  3. useSetRecoilState, the primary candidate when you just need to write state.

useRecoilState will trigger rerender of the component every time

useSetRecoilState only trigger once

原文地址:https://www.cnblogs.com/Answer1215/p/13737465.html