score:1
if you need to send some route state then the push
method takes an object.
const getprofile = (member) => {
console.log(member)
props.history.push({
pathname: '/member',
state: {
user: member,
},
});
console.log('----------- member------------')
}
additionally, member
is a functional component, so there is no this
, just use the props
object.
the route state is on the location
prop, not the history
object.
const member = (props)=> {
const [user, setuser] = usestate({});
const { state } = props.location;
// access state.user
also additionally, useeffect
callbacks can't be async
as these imperatively return a promise, interpreted as an effect cleanup function. you should declare an internal async
function to invoke. on top of this, the setuser
function isn't async
so it can't be awaited on.
the following is what i think should be the effects for populating the user
state and issuing side-effects:
// update user state when route state updates
useeffect(() => {
if (state && state.user) {
setuser(state.user);
}
}, [state]);
// run effect when user state updates
useeffect(() => {
const doeffects = async () => {
try {
const p = await incidentsinstance.usersprofile(state.user, { from: accounts[0] });
const a = await sninstance.getusersposts(state.user, { from: accounts[0] });
} catch (e) {
console.error(e)
}
}
doeffects();
}, [user]);
Source: stackoverflow.com
Related Query
- How can I redirect to another component in react and pass the state that I set in the previous component?
- How can I pass the state from one component to another and how can I modify the state?
- How to set state in parent from one child component and access the state in another child component using react and typescript?
- How to TEST async calls made in componentDidMount that set the state of React Component
- How do I manage state on a React component that can have state changed from the parent or from events upon it?
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- how to set react parent component state by a async function and then pass this state to child as props?
- How to take the input from a react component and pass the length of the input to another react component
- How can I pass the children of a function component to another function component in a react class?
- How can I pass a value from the backend to a React frontend and use that value in the CSS for the frontend?
- how to capture the file of an input element so that I can pass it as an argument to another function in react
- How can I pass props from one component to another using Link and router in react
- How to call a function that uses the state (which is set by another function) and updates state
- Using react, how can I create a function to set the state that takes the state name and value as arguments?
- How can I pass state from one component to set another state?
- How to use React Redux store in component that modifies and renders the state
- how can I set the reducer's return value to state object in component in react js
- How can I match data from an object and pass it as props to another component that displays dynamically?
- How can I connect a component that holds the state and a presentational component?
- How can I update State in React using the React-Select Component and User Selection?
- How we can maintain the state of logged in and loggedout users and share that state to homepage in react redux
- How to get images from e.target.files[0] by input id so that i can set the state of images and then post it via axios
- How can i pass props from a functional button component to another function component that displays the prop?
- How to retain and pass the new state values to another router component in ReactJS
- How to pass in a react component into another react component to transclude the first component's content?
- React - how to pass state to another component
- How do I wrap a React component that returns multiple table rows and avoid the "<tr> cannot appear as a child of <div>" error?
- React & Jest, how to test changing state and checking for another component
- How to pass a state className variable to another component in react
- How to set React component state and props from browser
More Query from same tag
- Pass methods with arguments to wrapper component
- How to insert setState value into useEffect hook?
- What is withRouter for in react-router-dom?
- Upload Image to Cloudinary with React and Apollo(GraphQL)
- Issue running react-redux with webpack
- Building a simple component for a 360 degree Image in React
- Jest/Enzyme testing Form component
- How to get count of duplicate objects in Array
- React class method not defined no-undef
- react-chartjs integration error. Cannot read property 'xLabels' of undefined
- Next.js-before-hydration, Next.js-hydration, and FCP
- How to add html i tag with next and previous button in react-pagination package
- undefined collection error when using simple schema and react (meteor app)
- Get request works with postman but with browser
- How to add PopOver on TimelineDot in MaterialUI for React?
- Footer Not Sticking to Bottom of React Page
- How do I run react and express with a single server.js file listening to a single port for production?
- react-bootstrap accordion issue in the arrow icons
- How to setState in reducer - React
- Remove DOM in react.js,
- How can I resolve this Leaflet error? getPixelWorldBounds()
- React hooks 'useState()' updater function with axios.post on form submits
- react using jquery to slideToggle
- Netlify-forms Contact Form submission 404 error
- Set ID for each div from Array
- Can you have a globally accessible function in a React App?
- React - HTML How to display my custom icon into <i> balise
- Change TextInput Style on Focus React Native Paper
- How to pass string and component as prop?
- Unable to render a react component