[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

posted @   Zhentiw  阅读(176)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2019-09-27 [Javascript] Construct a Regex to Match Twitter Mentions with Regexr
2018-09-27 [RxJS] Implement RxJS `switchMap` by Canceling Inner Subscriptions as Values are Passed Through
2018-09-27 [RxJS] Implement RxJS `mergeMap` through inner Observables to Subscribe and Pass Values Through
2018-09-27 [RxJS] Chain RxJS Operators Together with a Custom `pipe` Function using Array.reduce
2018-09-27 [RxJS] Implement the `map` Operator from Scratch in RxJS
2017-09-27 [Python] Different ways to test multiple flags at once in Python
2017-09-27 [Angular] Use :host-context and the ::ng-deep selector to apply context-based styling
点击右上角即可分享
微信分享提示