score:2
Use the useEnhancedReducer
hook introduced here.
Then you will have something like.
const [state, dispatch, getState] = useEnahancedReducer(reducer, initState)
Because dispatch
, getState
will never change, you can pass it to some hook without adding them to the dependence list or store them somewhere else to call them from outside.
There is also version of useEnhancedReducer
which supports adding middleware, in the same post.
Source: stackoverflow.com
Related Query
- Retrieve current state from useReducer outside React component
- Update component state from outside React (on server response)
- Set React component state from outside of component
- Access a React component method / state from outside the component
- Can't update React Component state when triggered from outside
- Update state of a functional component from outside of that component(on click of button in another file) in React
- React component initialize state from props
- React js change child component's state from parent component
- Call a React component method from outside
- Call a React component method from outside
- How to set React component state and props from browser
- Change react hook state from parent component
- How to initialize the react functional component state from props
- How to update the state of a sibling component from another sibling or imported component in REACT
- Updating Parent Component State from Child Component with UseState React Hook
- React Apollo: Dynamically update GraphQL query from Component state
- Can I use useReducer from outside component
- How to maintain react component state when goback from router?
- how and when to call a react component methods after state change from redux
- Accessing React state from outside
- How do I sync state from the DOM to my React Component in an Isomorphic Application?
- React: How to add onChange functionality inside of Function component using React Hooks? Need onClick event from a checkbox to influence input state
- Change the state when clicking outside a component in React
- Update a react state (array of objects) from a child component
- Trigger state change of a React component from Chrome extension on a Facebook post
- How to from one component set state another component in react native?
- How do I manage state on a React component that can have state changed from the parent or from events upon it?
- Sharing state from parent to child component in React
- Change state of React component from old external Javascript?
- React Final Form. How to set field value from component state
More Query from same tag
- How can I test index.js which uses react-redux connect and export exports items
- React Native: Getting data from one class to another
- How to get React state array to permanently update
- getting error while trying to deploy a React app to Azure App Service
- Updating context data from a wrapper around a provider in React
- React; cannot read property of undefined inside render > return()
- Redux-React : How to pass the updated state to function onChange?
- React parsing Unexpected token
- WebStorm - autocomplete React className attribute with quotes instead of object literals
- Can React context be mutated by nested component?
- Adding text into a text input onKeyPress react.js
- Trying to access a custom prop in styled components
- Typescript error when outputting key/value from mapped Object with Object.keys
- Animating out a React component before unmounting that has lost the props data it needs to display?
- React Router (Dom) v4 redirect to different route upon input enter key press
- How to change image on button after click reactJs
- horizontal scrolling react photo gallery
- How do i use data collection with gatsby and Netlify CMS
- If I was mapping thru a collection, and placing buttons for each doc, how could I grab the docID from the button to its function?
- How to set horizontal scroll position react
- Property 'checked' does not exist on type 'Switch'
- How do I use an Immutable.js List of objects in React with Typescript?
- Unable to add code blocks in Sanity CMS after I install the code-input plugin
- use of React.Lazy for services (non-component) type of code
- React hooks: Set state 'ModalVisible' but state does not update immediately
- Is this the correct way of using React.Suspense?
- Google Maps JavaScript API library must be loaded - convert solution for react functional component
- How can show and hide react components using hooks
- How to call react router DOM link inside a function call/manually
- React Router Authentication Redirection