score:-1
reactDOM.unmount(document.body);
reactDOM.render(<App />, document.body);
score:1
class App extends React.Component {
state = {
name: "",
select: "",
}
defaultState = {
name: "",
select: "",
};
formRef = React.createRef();
handleChane = e => this.setState( {
[ e.target.name ]: e.target.value,
} );
handleSubmit = ( e ) => {
e.preventDefault();
alert( JSON.stringify( this.state ) );
this.setState( this.defaultState );
this.formRef.current.reset();
}
render() {
console.log( this.state );
return (
<form ref={this.formRef} onSubmit={this.handleSubmit} >
<Input onChange={this.handleChane} />
<Select onChange={this.handleChane} />
<button>Send</button>
</form>
);
}
}
const Input = props => (
<div>
<input onChange={props.onChange} name="name" />
</div>
);
const Select = props => (
<div>
<select onChange={props.onChange} name="select">
<option>Choose one</option>
<option>Foo</option>
<option>Bar</option>
<option>Baz</option>
</select>
</div>
);
Source: stackoverflow.com
Related Query
- How can I change a child's state from the parent component
- How can I change the state of a parent component from a child component?
- How do I manage state on a React component that can have state changed from the parent or from events upon it?
- In React, how can a parent component set state from the response an async fetch function performed in a child component?
- How do I change the state of the parent component from the child component in Reactjs?
- how to prevent child component from reload when the parent state is change
- How can I set the state of my parent component from the child component when using react-router?
- How would I change the state in the parent component from the child in React?
- How can I update my child component state from the parent class in React?
- Can we pass setState as props from one component to other and change parent state from child component in React?
- Reactjs how to change the state of a component from a different component
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How to change the background color of a parent component from inside a child component in react, gatsby
- How to update the correct state value in a parent component that gets its value from a child component using hooks in react?
- How to pass input values from a child Form component to the state of its parent component for submission with react hooks?
- next.js how to change parent state from child component without triggering a button?
- How can I render Parent component again after update from the child component
- How can reset a React child component back to original state after it updates state in the parent
- How can I change the value of let from a component prop?
- In React, how can a parent change prop or state values on another component programatically?
- Calling a function to change state in parent component from the child component in react
- How to access the state of a child component from a parent class
- Not sure how to update parent state from the child component
- how can i change the parent iframe size from inside with javascript?
- How to access state from components to the parent component
- How can I set the parent component state based on children component checkbox value?
- How to change only a part of the state from child component react hooks
- How can I pass the state from one component to another and how can I modify the state?
- How can i update an Input field in Child component from the Parent Component
- Change state of parent component from Child component by extending the class
More Query from same tag
- How to use enum values as a type
- How can I test styles coming from sass with jest and react-testing-library?
- GraphQL with Apollo - how to use fetchMore
- kepler.gl state doesnt exist. You might forget to mount keplerGlReducer in your root reducer
- Component is not rendering again React JS
- List in React component not updating when item is removed from array
- Bootstrap modal closes while clicked on the modal content body
- Timeout on Axios Requests
- select cell in different column in react app
- How to allow <input type="file"> to accept only Lottie files?
- Recharts Y-Axis interval issue
- Problem with reducer function in useReducer hook
- Leaflet GeoJSON Turf: × Error: Invalid LatLng object: (undefined, undefined)
- React-Testing-Library Setup for Redux, Router and Dynamic Modules using TypeScript
- Page is not redirecting to updated URL
- How to share current URL in ReactJS
- Is it possible to use a custom class name generator for styled components in MaterialUI?
- Getting warning when i use withCookies()
- passing in a function as props
- How to fix the Argument of type 'Date[]' is not assignable to parameter of type '(prevState: undefined) in react
- How to pass Image object as props in React?
- Adding unique id attribute to img tag
- React Bootstrap Modal Popup in Axios?
- Can't scale SVG in React
- Fetch data into React component and render it
- React cannot read object of custom js file
- Login is not a function after logging out then trying to log back in
- Conditionally import css packages based on next-themes
- Transforming Material-UI Drawer with makeStyles into one with styled-component
- use openCv.js with next.js