Let’s add the required constants to the file src/external/redux/constants
.
DELETE_LIST
, DELETE_WORD
- the value of all constants is equal to their name.
Export two more functions from src/external/redux/actions
: deleteWord
, deleteList
.
Each must return an object with fields type
and payload
.
The type
field is equal to the constants DELETE_WORD
and DELETE_LIST
, respectively.
payload
equals a single argument to each function, respectively.
In the same place we will add a request method fetchWord
with three arguments: the word to search for, listKey
and the object navigation
.
This method must return an asynchronous function with one dispatch
argument.
First dispatch the action for the loading
field with the value true
.
Then we make a request using fetch, the url of which is obtained from the getFetchWordEndpoint
method.
If the answer is no error, dispatch the addWord action with the result of the response and listKey
, dispatch setError
with the argument null
and call the method navigation.goBack
.
If the response is an error, dispatch the setError
action with this error.
Always dispatch setLoading
with the value false
at the end.
This task is part of the Full-Stack JavaScript Course.
If you have any issues with it, you can ask for community help below the post.
Feel free to help others if you’ve already solved the task.