Skip to content

Commit

Permalink
fix: react form examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcamargo committed Jan 20, 2021
1 parent bc4adb4 commit 28e314b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/scripts/react/components/form/form.doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
const initialData = { name: '', email: '', message: '' };
const [data, setData] = useState(initialData);

const onDataChange = ({ name, value }) => {
const onDataChange = ({ target: { name, value } }) => {
setData({...data, [name]: value});
};

Expand Down Expand Up @@ -111,10 +111,8 @@ module.exports = {
return function(){
const [data, setData] = useState({});

const onDataChange = ({ name, value }) => {
setData(prevState => {
return Object.assign(prevState, { [name]: value });
});
const onDataChange = ({ target: { name, value } }) => {
setData({...data, [name]: value});
};

const onSubmit = () => {
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/react/components/input/input.doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
return function(){
const [value, setValue] = useState('');

const onChange = ({ value }) => setValue(value);
const onChange = ({ target: { value } }) => setValue(value);

return (
<>
Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = {
return function(){
const [value, setValue] = useState('Pitsby');

const onChange = ({ value }) => setValue(value);
const onChange = ({ target: { value } }) => setValue(value);

return (
<>
Expand Down Expand Up @@ -101,7 +101,7 @@ module.exports = {
return function(){
const [value, setValue] = useState('');

const onChange = ({ value }) => setValue(value);
const onChange = ({ target: { value } }) => setValue(value);
const onSubmit = evt => {
evt.preventDefault();
setValue('');
Expand Down Expand Up @@ -135,7 +135,7 @@ module.exports = {
return function(){
const [value, setValue] = useState('');

const onChange = ({ value }) => setValue(value);
const onChange = ({ target: { value } }) => setValue(value);

return (
<Row>
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/react/components/textarea/textarea.doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
return function(){
const [value, setValue] = useState('');

const onChange = ({ value }) => setValue(value);
const onChange = ({ target: { value } }) => setValue(value);

return (
<>
Expand Down Expand Up @@ -63,7 +63,7 @@ module.exports = {
return function(){
const [value, setValue] = useState('Pitsby');

const onChange = ({ value }) => setValue(value);
const onChange = ({ target: { value } }) => setValue(value);

return (
<>
Expand Down Expand Up @@ -91,7 +91,7 @@ module.exports = {
return function(){
const [value, setValue] = useState('');

const onChange = ({ value }) => setValue(value);
const onChange = ({ target: { value } }) => setValue(value);
const onSubmit = evt => {
evt.preventDefault();
setValue('');
Expand Down Expand Up @@ -127,7 +127,7 @@ module.exports = {
return function(){
const [value, setValue] = useState('');

const onChange = ({ value }) => setValue(value);
const onChange = ({ target: { value } }) => setValue(value);

return (
<Row>
Expand Down
7 changes: 1 addition & 6 deletions src/scripts/react/components/textarea/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export const Textarea = ({ name, value, disabled, required, onChange }) => {
className="pd-textarea"
disabled={ disabled }
required={ required }
onChange={ evt => onTextareaChange(evt, onChange) } />
onChange={ onChange } />
);
};

function onTextareaChange({ target }, onChange){
const { value, name } = target;
return onChange({ name, value });
}
3 changes: 1 addition & 2 deletions src/scripts/react/components/textarea/textarea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ describe('Textarea', () => {
const onChange = jest.fn();
const wrapper = mount({ onChange });
wrapper.simulate('change', evtMock);
const { name, value } = evtMock.target;
expect(onChange).toHaveBeenCalledWith({ name, value });
expect(onChange).toHaveBeenCalledWith(evtMock);
});
});

0 comments on commit 28e314b

Please sign in to comment.