score:0
i'm not sure but try this :
first update this line in the parent component :
if (userdata.me.id !== notedata.note.author.id) {
return navigate(`/note/${id}`, { replace: true });
}
then in the child component i would like to do this :
const noteform = ({content = "", action}) => {
const [value, setvalue] = usestate(content);
const onchange = event => {
setvalue(event.target.value);
};
.....
// then in the render of text area we only need a flat state contains value
<textarea
required
type="text"
name="content"
placeholder="note content"
value={value}
onchange={onchange}
/>
but if it doesn't work , try to set the state inside useeffect based on the value of content, dont't forget to give the state an initial value "":
useeffect(() => {
if (content) {
setvalue(content);
}
}, [content]);
Source: stackoverflow.com
Related Query
- How to use useNavigate() before rendering component with useState() in React
- How to use useNavigate in combination with useEffect in React component to conditionally redirect when component renders?
- How to use callback with useState hook in react
- How to use children with React Stateless Functional Component in TypeScript?
- How to test decorated React component with shallow rendering
- How to use React links when rendering content with dangerouslySetInnerHtml?
- How to use React Context with useState hook to share state from different components?
- How to use jest.spyOn with React function component using Typescript
- How do you correctly use React.lazy() in Typescript to import a react component with a generic type parameter?
- How to use React Component with Tether.js/drop.js
- How to use RouterLink with Microsoft FluentUI React Link component
- How to use useState hook in React with typescript correctly?
- How do I use types defined by @types/redux-form in React component with Field and FieldArray?
- How to use ternary operator within the jsx of a react component along with typescript?
- How to use Jest for testing a react component with localStorage?
- How can I make an axios get request wait before rendering my react component
- How to conditionally pass optional props to component when we use React with Typescript?
- How to use HTML with JS in React app to export component
- How to use @apply in a react component with css modules
- how to use Link to with Tabs component React from Antd Design
- How to use react-alert with React component that is defined as ES6 class
- How to use React Ref with Styled Component
- How to properly use ref with a React class component and styled-components?
- How to use jest.spyOn with functional react component
- How to properly use TypeScript types with a Styled Component canvas on React
- how to get, by a get from axios, data in useState with react functionnal component
- How use component react created with enzyme example mocha in browser?
- How to use vanilla JS with React component (zoom to bounds on load react mapbox gl)
- How to use a state value with map function to display repeat ui in react component
- How to make pass a test case which use enzyme shallow with contains when a React component has an event handler
More Query from same tag
- React Class passing stale props to Child stateless component
- How to send values from api after maping react hooks
- React: Pass function property down to pure child component - Rerendering
- How to filter data and show it on top of the array?
- Using a React State object as key to another value
- How to add type FunctionComponent to React functional component using the "function" syntax and not "const"?
- JSON.stringify returns "" React
- token from localStorage is undefined react
- Sorting objects in an array by its values using onClick
- Index.js Error: UserForm(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null
- switch statement evaluating incorrectly in styled-components
- How to render parts of a React component in multiple places in a parent component (Render component in the middle of another component)
- Update array but retain existing array in map
- how to toggle a class on a div in react project for opening a mobile menu in mobile
- How can I get the current map center coordinates using getCenter in @react-google-maps/api?
- How to get the value of the highlighted item with react-select-plus?
- How to connect mapstatetoprops and mapdispathctoprops in React and Redux
- how to access router params in getInitialProps stateles component in nextjs
- React useEffect inside async function
- Material ui card open in new tab on Ctrl+click
- actions not working inside componentDidMount
- Trying to use GoogleSignIn in React Native then Possible Unhandled Promise Rejection (id: Error: DEVELOPER_ERROR
- OnClick on child div should not trigger parent div's onClick method for a particular child
- What's the best way to fetch data on form submit in Next.js?
- React-Native: React could not be found within project or in these directories
- initialize state react, to solve undefined when the page first rendered
- Creating a React component
- Why does this function variable have initial values?
- React get state/data of parent element when click on child element
- How to display keystroke on page using react