{"repo":"davidkpiano/useEffectReducer","free":true,"listed":false,"github":"https://github.com/davidkpiano/useEffectReducer","clone":"git clone https://github.com/davidkpiano/useEffectReducer.git","description":"useReducer + useEffect = useEffectReducer","language":"TypeScript","stars":805,"topics":["react","hook","reducer","state","hacktoberfest"],"license":"MIT","category":"ui-components","readme_excerpt":"useEffectReducer A React hook for managing side-effects in your reducers. Inspired a looooong time ago by the useReducerWithEmitEffect hook idea by Sophie Alpert. If you know how to useReducer , you already know how to useEffectReducer . Table of Contents - Installation - Quick Start - Named Effects - Effect Implementations - Initial Effects - Effect Entities - Effect Cleanup - Replacing Effects - String Events - API - useEffectReducer hook - exec(effect) - exec.stop(entity) - exec.replace(entity, effect) - TypeScript Installation Quick Start An effect reducer takes 3 arguments: 1. state - the current state 2. event - the event that was dispatched 3. exec - a function that captures effects to be executed and returns an effect entity How It Works Internally, useEffectReducer abstracts this pattern: Instead of being implicit about which effects are executed and when, you make this explicit in the effect reducer with exec . The hook then properly executes pending effects within useEffect() . Named Effects A better way to make reusable effect reducers is to use named, parameterized effects . Pass an effect object to exec(...) and specify the implementation as the 3rd argument to useEffectReducer : Effect Implementations An effect implementation receives 3 arguments: 1. state - the state at the time exec(effect) was called 2. effect - the effect object 3. dispatch - the dispatch function for sending events back to the reducer Return a cleanup function to dispose of the effect: Ini","default_branch":null,"files":null,"tree":[],"storefront":"/r/davidkpiano","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/davidkpiano/useEffectReducer/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}