Skip to content

Commit

Permalink
fix: example in the docs;
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed Oct 16, 2019
1 parent 652b318 commit 7f54cad
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions docs/useMediatedState.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ A lot like the standard `useState`, but with mediation process.
import * as React from 'react';
import { useMediatedState } from '../useMediatedState';

const InputMediator = s => s.replace(/[\s]+/, ' ');
const inputMediator = s => s.replace(/[\s]+/g, ' ');
const Demo = () => {
const [state, setState] = useMediatedState('', InputMediator);
const [state, setState] = useMediatedState(inputMediator, '');

return (
<div>
<div>You will not be able to enter more than one space</div>
<input
type="number"
min="0"
max="10"
value={state}
onChange={(ev: React.ChangeEvent<HTMLInputElement>) => {
setState(ev.target.value);
}}
<input type="text" min="0" max="10"
value={state}
onChange={(ev: React.ChangeEvent<HTMLInputElement>) => {
setState(ev.target.value);
}}
/>
</div>
);
Expand Down

0 comments on commit 7f54cad

Please sign in to comment.