jchen42703 / translator-app

Web app for editing machine translations efficiently. [WIP]
Apache License 2.0
1 stars 0 forks source link

Is it necessary to use Redux? #16

Closed jchen42703 closed 3 years ago

jchen42703 commented 3 years ago

What if we let Translator hold the EditorState and pass it as a prop to both InputEditor and TranslatedDisplay? Is this possible?

If so, then we wouldn't need to keep dispatching EditorState for the align paragraphs feature?

jchen42703 commented 3 years ago

InputEditor would need to update the parent state as a child component:

jchen42703 commented 3 years ago

Another example:

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>
        )
    }
}
jchen42703 commented 3 years ago

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: