随笔分类 - React
摘要:With React hooks it's common to write callback functions in our component body. Event handlers are a common example of this. Most of the time they wor
阅读全文
摘要:In addition to storing DOM references, the useRef hook can be used to store values without re-rendering the component. If you have a class component t
阅读全文
摘要:Using React hooks like useState makes it easy to manage things like a shopping cart, but that state may only be available one instance at a time. What
阅读全文
摘要:function useState<S>( initialState: S | (() => S), ): [S, Dispatch<SetStateAction<S>>] Example: function useDarkMode() { // ... const returnValue: [st
阅读全文
摘要:Highlights: Solve the complexities of write Redux (actions, reducers, selector...middleware...) Solve the immutable pattern with nested spread operato
阅读全文
摘要:If you find yourself filling out the same form over and over again, or working through a weird workflow to enable certain features in your app just to
阅读全文
摘要:You often want to ignore values until the user performs a certain action. This lesson walks through setting up an allowWhen broadcaster that will only
阅读全文
摘要:To display a sequence of values in React, we can use our mapSequence operator, wrap it around a broadcaster, then pass that new broadcaster into our u
阅读全文
摘要:Instead of always combining useState and useEffect, when can create a utility useBroadcaster hook which allows us to pass in a broadcaster. export let
阅读全文
摘要:https://epicreact.dev/css-variables/ Code body[data-theme='light'] { --colors-primary: deeppink; --colors-background: white; } body[data-theme='dark']
阅读全文
摘要:We should always ship fast experiences to our users, but sometimes something slips through our PR review process and our users start having a slow exp
阅读全文
摘要:For the follow code: function Cell({row, column}) { const state = useAppState() const cell = state.grid[row][column] const dispatch = useAppDispatch()
阅读全文
摘要:The way that context works is that whenever the provided value changes from one render to another, it triggers a re-render of all the consuming compon
阅读全文
摘要:const defaultInitialState = {status: 'idle', data: null, error: null} export function useAsync(initialState) { const initialStateRef = React.useRef({
阅读全文
摘要:// Window large lists with react-virtual // http://localhost:3000/isolated/final/04.js import React from 'react' import {useVirtual} from 'react-virtu
阅读全文
摘要:To understand lazy loading in React, we need to think in two steps. 1. Use dynamice import: to load script 2. Use React.lazy to load dynammice import,
阅读全文
摘要:The useDebugValue hook will not effect your user experience but is instead aimed at improving the developer experience. When building your own custom
阅读全文
摘要: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 d
阅读全文
摘要:When consuming asynchronous selectors in Recoil, you're going to need to tell React what to render while the API is fetching its data. One way to solv
阅读全文
摘要:In this lesson, we're going to learn how to create Recoil selectors that accept arguments. These are made possible using the selectorFamily utility fu
阅读全文