From fd813aa738f0961aeee003cc2b5bafe3fdbc0f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Thu, 13 Dec 2018 10:33:36 +0100 Subject: [PATCH] add limited word text area --- snippets/LimitedWordTextArea.md | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 snippets/LimitedWordTextArea.md diff --git a/snippets/LimitedWordTextArea.md b/snippets/LimitedWordTextArea.md new file mode 100644 index 000000000..662ec93dd --- /dev/null +++ b/snippets/LimitedWordTextArea.md @@ -0,0 +1,62 @@ +### LimitedWordTextArea + +Renders a textarea component with a word limit. + +Use the value of the `value` prop to determine the initial `state.content` and `state.wordCount` and the value of the `limit` props to determine the value of `state.limit`. +Create a method, `handleChange`, which trims the `event.target.value` data if necessary and uses `Component.prototype.setState` to update `state.content` and `state.wordCount`, and bind it to the component's context. +In the`render()` method, use a`
` to wrap both the` +

{this.state.wordCount} / {this.props.limit}

+
+ ); + } +} +``` + +```jsx +ReactDOM.render( + , + document.getElementById('root') +); +``` + +< !--tags: input,state,class -- > + +< !--expertise: 0 -- > +