Skip to content

Instantly share code, notes, and snippets.

@biligunb
Last active October 15, 2021 08:07
Show Gist options
  • Save biligunb/bd9eaa004b4e1bac586206a4eb82211f to your computer and use it in GitHub Desktop.
Save biligunb/bd9eaa004b4e1bac586206a4eb82211f to your computer and use it in GitHub Desktop.
Stateless & Stateful component
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