Upload 6.8
This commit is contained in:
28
part6/redux-anecdotes/src/components/Form.js
Normal file
28
part6/redux-anecdotes/src/components/Form.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import React from 'react'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import { addAnecdote } from '../reducers/anecdoteReducer'
|
||||
|
||||
const Form = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const handleNew = (event) => {
|
||||
event.preventDefault();
|
||||
const content = event.target.anecdote.value;
|
||||
event.target.anecdote.value = '';
|
||||
dispatch(addAnecdote(content));
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>Add new anecdote</h2>
|
||||
<form onSubmit={handleNew}>
|
||||
<div>
|
||||
<input name="anecdote" />
|
||||
</div>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Form;
|
||||
Reference in New Issue
Block a user