score:1
Accepted answer
keep the state only in the parent, and pass it down as a prop, as well as another prop - a function which, when called, sets the age in the parent.
you also need to correct the shape of onchange
- it accepts an argument of the event, not of the new value.
// in creategame
const setage = i => (newage) => {
setquestions([
questions.slice(0, i),
{ ...questions[i], age: newage },
questions.slice(i + 1),
]);
};
// ...
<grid item lg={5}>
<selectfield age={questions.age} setage={setage(index)} />
</grid>
export default function selectfield({ age, setage }) {
// ...
<select
value={age}
onchange={e => setage(e.currenttarget.value)}
score:0
you can go through these steps
- step 1 make an onchange event listener
<selectfield onchange={handlequestion}/>
- step 2 use hooks to make a state inside functional component
const [question, setquestion] = usestate("")
- step 3 make the method that you had called in step 1
const handlequestion = () =>{
//first get the value coming fron the onchange listener
console.log(e.target.value);
//set the state to the question
setquestion(e.target.value)
}
- step 4 pass the value to the question
<textfield
value={question}//pass the questions state value here
/>
Source: stackoverflow.com
Related Query
- How can i get the min value and max value from the rc slider third party component
- How can I get the value of a component I created?
- How can I get the value from a component to another?
- How can I get the state value in the reducer of createSlice?
- How can I get the element of another component in React.js?
- How can I get the value from an animated or interpolated value in React Native?
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How can we get the text field value during onSubmit method in latest react-hooks-form
- How can get Value from child component in react?
- How can I change the value of a property on the call of a reusable component on Reactjs?
- How to get the value of react component - AceEditor
- How can I get more than one value from the Redux store in a single statement?
- How can i get the value of my input radio button in react?
- Can i get the value of my Key inside my react component
- React SSR : How can my component get the URL search URL parameters in its render method
- How can I get the daterange picker to return the value
- How can I change the value of let from a component prop?
- How can I get a component to update on path change while using the same route and component?
- How to get the value from button group in react component
- How can I get the value of the Autocomplete Select of material-ui?
- How can I get the value of the checkbox to be saved in the firestore?
- How does my useContext component know to get the value in App.js?
- How can I get the value in the parent from a child components(From Inputs)
- How to get value of a dynamically created component in react.js?
- How to get the value of from a list in a component in ReactJS?
- How can I request the value I get from the user to the backend api using react?
- How can I get the value of a select form element?
- How can I get the Icon to be clickable and let it allow changing the value inside Input?
- How to get the return value of parent function to child component in react (Using props)
- How can I show dynamically a component based on the value of the state
More Query from same tag
- React Application Requiring Access to 3000+ Entries from Contentful API
- Link spring boot with react
- Is it possible to show all <select> <option>s as a toggle?
- can not put file in redux array
- Error validation with Material UI Autcomplete & React hook form
- react-stripe-elements not detecting Stripe.js
- Undefined variable using .map() react
- ReactJs app crashes with error "Consider adding error boundaries to your tree"
- request data, pass it to another component and return it in react
- ReactJs - TypeError: Cannot assign to read only property 'name' of object '#<Object>'
- Express - `req.body` is always empty
- React how to ignore onClick for child element
- Webpack error - can't resolve loader in 'tmp/build...'
- send get request with id in redux saga
- ReactJS & TypeScript - Get one random value of array
- How to import Sass modules in Next.js components
- Easy Peasy state managment - How to fetch and pass data correctly?
- React history push data as parameter to page
- Is it possible that React modifies a reference?
- Typescript generic type for nested object properties
- How to display different component after button click using React-Hooks?
- react redirect issue I'm getting cannot read setState of undefined
- Unable to get object/array size
- Go Api returning Unauthorized
- Reading firestore sub-collection data in react - how to set a parent id in the sub-collection where query
- Issue to handle React-Hook-Form errors object in combination with es6 literal templates
- Formik form template for xml document creation
- Get values from useEffect hook and display in React's functional components
- React Router is leaving my main page loaded when trying to load other pages
- How to check states after sending request in server?