score:1
Accepted answer
you have options when trying to correctly bind a method to an inline callback:
also: you're assumption that omitting the mapdispatchtoprops
results in the dispatch
being mapped to the props as this.props.dispatch
is correct.
use the arrow function:
onpress={this.handlelogin(dispatch)}
to:
onpress={() => this.handlelogin}
// this
is lexcially bound inside an arrow function, yay!
use bind
in the constructor function:
constructor(props){
super(props)
this.handlelogin = this.handlelogin.bind(this);
}
use bind
within the inline callback:
onpress={this.handlelogin.bind(this);}
Source: stackoverflow.com
Related Query
- How to get reference to the dispatch method from a component method in my react-native redux app
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- how to get a Component variable from another component but their both in the same file React
- How to get a reference to react component from a document event?
- React SSR : How can my component get the URL search URL parameters in its render method
- How to get the value from button group in react component
- How to get the reference for new window object from a Component which opens the window?
- Can I get a reference to jsx react component so I can I forceUpdate/rerender react component from the chrome developer console?
- how to get the data from child component in stepper in react material ui?
- How to reference a React Component class from outside the render function?
- how to get the data from a component within a form in react
- How do you get the Tag from a React Component
- How do I get the value from a React Img component
- React : how to get input value from one component to make the ajax call in another component?
- How to get the data from dropdown component in React and update state?
- Making an HTML string from a React component in background, how to use the string by dangerouslySetInnerHTML in another React component
- How to get the data from React Context Consumer outside the render
- How to get refs from another component in React JS
- How to initialize the react functional component state from props
- How to pass the match when using render in Route component from react router (v4)
- How to update the state of a sibling component from another sibling or imported component in REACT
- How can I get a variable from the path in react router?
- React - Triggering a component method from another component, both belonging in the same render()
- How to get value from a react function within a react component
- How to get the react component instance corresponding to event.target element in a click handler?
- react - how do I get the size of a component child elements and reposition them
- How to get a React Component reference to change its class using classList?
- How does React know the component is removed from the DOM?
- How to get the DOM node from a Class Component ref with the React.createRef() API
- How To Declare TypeScript Static Method From React Functional Component
More Query from same tag
- remove the warning of empty array if data is exist
- If nodejs is Server side scripting language then how it is used in ReactJs or any other Front end language
- Trouble getting CORS to work between CodeIgniter and React app
- Yotpo reviews and galleries not loading on page change
- Storybook requires default Ant Design component to be exported for styling to be applied
- How to get selector working in redux-form app?
- How to pass data to another component not in the URL with React Router
- Search bar and suggestions with matches based on JSON object in React
- How to dynamically change page title and description in ClojureScript / Reagent
- Tab navigator icons in React Navigation
- How do I escape the color character (:) inside the path, with React-Router V4?
- Material UI Autocomplete default value of empty string
- How to avoid setState in useEffect hook causing second render
- My Table is not re-rendering even it is calling useEffect
- Getting undefined with jest mock testing axios
- How to prevent dublicated items in mongoDB when an item is updated
- How to use react-router BrowserRouter in a static index.html file
- React - input date field not updating value in state
- Each child in an array or iterator should have a unique "key" prop. React JS Error
- How to type the StaticRouterContext from react-router-dom in Typescript?
- How to add a React component to a loop?
- Add retry inside an ajax call within a Promise
- How to install plugin-export-default-from to Babel in react project
- React component not re-rendering on URL parameter change when using useEffect hook to fetch data
- Selenium: Clicking on React button
- Dispatch is not a function in Server Side Rendering
- Do I need to use revalidate key in getStaticProps Next.JS for lists in page?
- I am getting "TypeError: Cannot read property 'username' of undefined" whenever I try to access record.username
- How to parse query string in react-router v4
- How to Deploy Strapi and React at one hosting?