Last active
October 15, 2021 08:07
-
-
Save biligunb/bd9eaa004b4e1bac586206a4eb82211f to your computer and use it in GitHub Desktop.
Stateless & Stateful component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { Child } from './Child'; | |
class Parent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { name: 'fromStateful' }; | |
this.changeName = this.changeName.bind(this); | |
} | |
changeName(newName) { this.setState({ name: newName }); } | |
render() { return <Child name={this.state.name} onChange={this.changeName} /> } | |
} | |
ReactDOM.render( <Parent />, document.getElementById('app') ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment