DefinitelyTyped/types/react-rte/react-rte-tests.tsx
2018-12-09 21:17:22 +11:00

34 lines
804 B
TypeScript

import * as React from "react";
import RichTextEditor, { EditorValue } from "react-rte";
interface Props {
onChange: (val: string) => void;
}
class MyStatefulEditor extends React.Component<Props, any> {
state = {
value: RichTextEditor.createEmptyValue()
};
onChange = (value: EditorValue) => {
this.setState({value});
if (this.props.onChange) {
// Send the changes up to the parent component as an HTML string.
// This is here to demonstrate using `.toString()` but in a real app it
// would be better to avoid generating a string on each change.
this.props.onChange(
value.toString('html')
);
}
}
render() {
return (
<RichTextEditor
value={this.state.value}
onChange={this.onChange}
/>
);
}
}