Skip to content

Instantly share code, notes, and snippets.

@dovidweisz
Created February 5, 2019 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dovidweisz/7d065cbeb3eec2424bdd5110fddde5b0 to your computer and use it in GitHub Desktop.
Save dovidweisz/7d065cbeb3eec2424bdd5110fddde5b0 to your computer and use it in GitHub Desktop.
export class TranslationWidget extends Component {
constructor(props, c) {
super(props, c);
this.state = {
items: this.props.value
};
}
onChange(key, value) {
this.setState({
items: {
[key]: value
}
});
}
render() {
return (
<div>
{Object.entries(this.state.items).map(([key, value], i) => (
<div key={key}>
<label for={labelr(key)}>{key}</label>
<input
type="text"
name={labelr(key)}
value={value}
onChange={event => this.onChange(key, event.target.value)}
/>
</div>
))}
<button onClick={() => this.props.onChange(this.state.items)}>
Save Changes
</button>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment