Closed jchen42703 closed 3 years ago
InputEditor
would need to update the parent state as a child component:
<MyChildComponent setState={(s,c)=>{this.setState(s, c)}} />
class Parent extends React.Component {
state = {text: ""}
updateText = text => {
this.setState({text: text})
}
render () {
return (<Child updateText={this.updateText}>)
}
}
class Child extends React.Component {
render () {
return (
<button
onClick={
() => this.props.updateText("updated state from child component")
}
>Update State</button>
)
}
}
Still migrating to this change b/c it doesn't matter if we break encapsulation for Translator
's child components. It's not like TranslatedDisplay
and InputEditor
will be used on the web app more than once. :shrug:
What if we let
Translator
hold theEditorState
and pass it as a prop to bothInputEditor
andTranslatedDisplay
? Is this possible?If so, then we wouldn't need to keep dispatching
EditorState
for the align paragraphs feature?