score:2
I agree with user1628461, but if your application grows, it can be problematic to repeatedly pass the store as an argument.
A possibility you have is to first initialise your store, to then pass it as parameter when initialising your helper class. This way you can save a reference to the store, its observables, and access it when needed. See example:
App.jsx
import Store from './store.jsx'
import Helper from './helper.jsx'
const myStore = new Store();
const myHelper = new Helper(myStore);
myHelper.doSomething();
helper.jsx
export default class Helper {
constructor(store){
this.store = store;
}
doSomething() {
// do something with the store
this.store.useAction();
this.store.anObservable = 'modified';
}
}
Source: stackoverflow.com
Related Query
- Access MobX state outside of React Components?
- How can I access a functional components state outside the component? - React
- Mobx state is lost when other React components access the store
- access token from auth0provider outside of react components
- How to test react components with mobx observable state
- export function inside react component or access state in same file outside of component
- Access a React component method / state from outside the component
- React access state after render with functional components
- Is it possible to access state variable outside of react render function?
- How to access a parent components state in react
- How to access state / functions outside of react component
- Trying to access state outside of a function in React
- React Redux - Access state between two components
- How to access a child's state in React
- What is the best way to access redux store outside a react component?
- Access React Context outside of render function
- How do I access store state in React Redux?
- Update component state from outside React (on server response)
- Can you pass down state to child components with React Hooks?
- Set React component state from outside of component
- React Native can't access this.props outside of render() method
- Access Formik's values outside of component | React
- React router v4 - How do you access the state that is passed via Redirect?
- How to access state when component unmount with React Hooks?
- react router v6 navigate outside of components
- using mobx with react functional components and without decorators
- How to communicate UI state changes between React components with Redux?
- Access Redux store outside React when using next-redux-wrapper
- Access props sent to components along with Redux state data
- How to keep React components state after browser refresh
More Query from same tag
- displays channels[object Object] instead of the real values
- How to display images from api in nextjs
- Building a table in react
- Webpack 4 devtool option does not work with webpack-dev-server
- React nested map sequential render with setTimeout
- Problem in implementing Search Filter in Reactjs- Trigger issues
- React onClick stops working after dialog has been shown
- Map Icons to Categories from API Call React Typescript Frontend
- Why I can't set and change my entire state with dispatcher like that?
- Trigger onClick event of button on dynamically generated html in ReactJS
- How can I access the ref of the BaseComponent or any level of the components?
- How to use hover not included in the react code?
- Can't display base64 image in react?
- JS/ReactJS - Assigning a new variable changes the original
- ReactJs mapStateToProps
- Optimize rendering loads of components in react
- Webpack Extract CSS for Production, Inline for Development
- React doesn't re-render on state change
- React - react-router-dom two Route conflict
- Autorization token from React doesn't pass Java Spring Boot filter
- Open New Link with Card Click (ReactJS)
- How to render one array item based on name props in React
- Use React fetch to call Dango REST getting a 403 response
- Error when using CanvasJS in a NextJS app
- babelify pipe results in: The code generator has deoptimised the styling of "/.../jquery.js" as it exceeds the max of "100KB"
- How can I use the context provider api and typescript without correcting me all the time
- how to move focus to an item in react js?
- Reactjs possible to change onclick function name like changing props
- How to wait for javascript promise to return value before continuing execution?
- How can I setup some print styles using MUI 5.5.2