score:1
there has to someplace where i have to check saying "hey if the props have changed, reset the state with the new props for edit???
yes you can use react.useeffect
hook on the special prop or array of props, then when that/those prop(s) change the internal hook function will be fire.
e.g. :
const mycomponent = (props) => {
let [mystate,setmystate]= react.usestate(null);
react.useeffect(()=>{
setmystate(props.prop1);
},[props.prop1]);
return ...
}
Source: stackoverflow.com
Related Query
- React.js Using the same FORM for creating a NEW db object and EDIT various objects
- Good practices for using the same form components for both create and edit pages
- Error when creating new object from existing one using `...`: In this environment the sources for assign MUST be an object
- Approach for different HTML structure with React and using the same components
- How to hide a column on REACT Material table in all rows and show it on Edit for the Particular Row I am editing and Add Operations on new row adding?
- using redux and redux-persist in react app: after submitting the form, store create a new and empty object
- Using same react component for add and edit
- Unable to use the same form component for Add or Edit Mode with React & Redux
- react native post form data with object and file in it using axios
- How to do POST in FORM Submit using reactjs and pass the object value into REST service?
- CDN links for React packages and how to import it when using react using the scripts from CDN
- Reactjs: Using same form for add and update
- How to use the same port for React Js and Node Js?
- Is there a clean way to conditionally load and render different components for the same React Router route?
- What is the general practice for express and react based application. Keeping the server and client code in same or different projects/folders?
- react redux: still getting empty object for this.props when using Connect for mapStateToProps and mapDispatchToProps
- Using the same component for different Routes with React Router
- How to serve index.html for React and handle routing at the same paths?
- Dynamic form returns the same value for the first and second input
- Minified React error #310; use the non-minified dev environment for full errors and additional helpful warnings using Chrome through Selenium in React
- creating common header and sidebar across all the page using react router
- How do I get my HTML form date input to only allow specific days of the week to be chosen using JavaScript, React and HTML?
- How do I correctly add data from multiple endpoints called inside useEffect to the state object using React Hooks and Context API?
- Eslint for a express and react project in the same project
- Dynamically create checkboxes and add change handlers for the same : Semantic-ui-react + React
- Can I use mock data and proxy api data at the same time in my react project when using node express as a proxy server?
- Creating and using an interface for a history-object in React Typescript?
- I have this `div` on my home page and want it to move with me when I scroll, I am using react for the website btw
- Counting duplicates in object array and storing the count as a new object have error !!! react js
- Why doesn't the loader show on the second test when I run the same test twice in jest, using react testing library, react.lazy, and suspense?
More Query from same tag
- TypeScript generics: Props with union type in React
- Where is the best practice to wait for data fetching and handle logic after?
- How to add edit button and function in react.js
- Hiding/Obfuscating reactjs code of .jsx file type?
- Lumen API CORS Ajax 405 Method Not Allowed
- Inline SVG background image does not work in React.js
- React: What happens on consecutive renders where a list shuffles?
- how can i add setinterval function inside React new array state
- How to convert a file to binary stream in Javascript?
- React: useReducer Hook trigger twice at first, NOT StrictMode
- (typescript) facing problem trying to pass font-awsome icon as object to child component
- How to fix the Argument of type 'Date[]' is not assignable to parameter of type '(prevState: undefined) in react
- Why is this is undefined when mocking event in React unit testing, using sinon.spy to mock function and enzyme.shallow render for React Component?
- React-Router - Uncaught TypeError: Cannot read property 'getCurrentLocation' of undefined
- How to pass a formik initialState value as a parameter to a function
- Too many re-renders when accessing data from an API in React
- Take input value from input and add to state
- Nuka-carousel custom arrow button
- State is undefined from other function
- react-konva - Handle transformer select, deselect and hover?
- How this.setState() (react.Component method) has access of his child's class state?
- Socket.io/React Chat App - Connection established
- Use maxResults from Youtube v3 APIs on React
- innerHTML works only once in my react app
- cannot read value of null in reactJs with linkedState
- Invalid hook call expo
- NextJs and dynamic routes - how to handle the empty parameter scenario?
- Getting [object Object] instead of actual object in React JS
- change order of react router links
- Using context in React while using useEffect