Skip to content

Instantly share code, notes, and snippets.

@vagrantsn
Last active April 8, 2019 20:51
Show Gist options
  • Save vagrantsn/e1125b3a331f243e1b642aa645140e0b to your computer and use it in GitHub Desktop.
Save vagrantsn/e1125b3a331f243e1b642aa645140e0b to your computer and use it in GitHub Desktop.
React Hooks Notes

React Hooks

  • useState
const [filter, setFilter] = useState('')
  • useEffect
useEffect(() => { return willUnmountCallback }, []) // '[]' prevents 'fn' from running on update. Executes on mount and willUnmount
  • useReducer
const [state, setState] = useReducer((state, newState) => ({ ...state, ...newState }), initialState)
  • useContext
const { logout } = useContext(GitHubContext)

Lazy and Suspense

React.lazy(() => <Component />) // Must have <Suspense> as HOC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment