DefinitelyTyped/types/react-rte/react-rte-tests.tsx
Nathan Shively-Sanders 6a273ee3da
Fix react-rte tests (#43588)
They check whether a method is defined on props, but the props type
doesn't make the method optional. Typescript now catches this error, so
I made the method optional.
2020-04-02 09:20:55 -07:00

34 lines
805 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}
/>
);
}
}