score:0
Accepted answer
you shouldn't get an undefined
, i think it is a problem with your input
component. i created a codesandbox with the same use case. as you type into the input, the child
component will change the state variable and the parent uses it.
it is completely fine to create a controlled child component like this.
score:0
seems like you have mis-spelled input
.
in react if the first letter of any html tag is capital, then it is treated as a custom react component.
simply rename this
<input autofocus placeholder="project name" value={projectname} onchange={({ target }) => { setprojectname(target.value) }} />
to
<input autofocus placeholder="project name" value={projectname} onchange={({ target }) => { setprojectname(target.value) }} />
Source: stackoverflow.com
Related Query
- Passing down use state values gives undefined
- Passing state down into a prop to child component, accessing it inline with "(this.props.(propHere))" coming up undefined due to "This"
- When I set state via useState in parent component, my props in the child I'm passing down to are undefined
- Passing state values to a component results in undefined errors
- non-serializable values were found in the navigation state when passing a function in params
- React Router v4 Redirect Passing State Undefined
- how can we use redux state in useState to set initial values
- Use of Context API vs CloneElement for passing down props for direct descendent
- How to fix: Context Provider not passing new context values down to children
- Using react HOC with a form. Passing common JSX and state down using a HOC
- Passing state down as props in React
- How to use multiple or two state values in one component or class file in react JS?
- React - Passing state from child to parent in drop down select
- React.js: Parent state values not passing into child properties + Fetch API data cannot be accessed
- React Redux - cannot use a pass down a component's method to the children - undefined error
- Should a React component use (fixed) values not on state or props?
- Use dynamically created react components and fill with state values
- Is passing the entire state down the react component a good pattern?
- reactjs: state properties are undefined after changing values
- TypeScript React: Use an array of strings as an index and get values from state
- React - passing state down
- Re-initializing react state array of objects leads to undefined values
- React Context Provider not passing down state into children
- React Router: props aren't passed down when directly accessing the URL of child component. Will I need to use the same state in both parent and child?
- Access Relay state without passing down props
- Use state from useContext component and access it from other component. It's fetching ok, but in the child component it gives an error
- How to update state in ReactJS and use the values at the same time
- Converting Class to Functional: Passing down state objects
- React | Error Passing Default Props Values When Destructuring Assignment is Undefined
- Passing the state from a Redux Slice to the Component is giving me undefined
More Query from same tag
- How to deploy a React + NodeJS Express application to AWS?
- How to insert data from client to server using socket.io?
- How to click on the button will show an item
- react-file-viewer does not load a new document on filePath change
- How to disable optimize warnings in webpack 2
- How to redirect to inside and external pages from ReactJS
- React-sortble-tree: how to find the parent node based on the current node: getNodeAtPath-way-of-working?
- How do I filter a to do list in React?
- Parsing error: Cannot find module '@babel/preset-react'
- How do I run a line of code after a function that contains setState when it is finished updating state?
- Add margin or padding to React-Bootstrap's Form.Label
- React counter getting out of sync when tab is not focused
- Axios post request with typescript issue
- createContainer does not receive data after route transitions (React Router)
- How to leave values already checked inside the Select?
- How to pass query parameters to another component in ReactJS?
- "You need to enable JavaScript to run this app"; response is html instead of json
- api call for class component using componentWillRecieveProps
- Cannot update a component while rendering a different component warning
- pass props to dynamic child component
- ReactJS and DraftJS, how to change font size on the fly?
- get solar year in react
- How do I render folders within a folder in one component in React(Next.js)?
- State management in React component when the business logic is outside of the component
- Material-ui's Switch component onChange handler is not firing
- how to automatically open the camera
- Material ui load select option data list from server response but when select a option can not return selected value
- Unexpected token, expected "}" Error while passing object from FetchMovie to MovieList component at line 7 of MovieList.js
- Stripe Card Element default postcode
- Can you help me to get rid of this? Warning: A component is changing an uncontrolled input of type search to be controlled