useResource
useResource
Basic hook for sending REST API from within React Component.
Basic usage
GET request
OPTIONS request
DELETE request
POST request
type application/json
type formdata
tip
Please note, that in case there is an instance of File in your request payload, resource module will automatically converd Request body to Formdata.
Dynamic URL and query params
You can pass the filters object as a second argument in create, update, replace actions to send API with dynamic URL and query params
PATCH request
PUT request
Request with dynamic URL
You can use dynamic URL sintax to specify API endpoint.
note
After each API call resource module will store URL params from the latest API call in filters object
Request with query params
info
To send HTTP requests with query params you need to define all possible queries that will be used using queries configuration
caution
All other data that is not described in queries resourceConfig will be omited
note
After each API call resource module will store query params from the latest API call in filters object
Modify data
Modify loading
Modify errors
Modify filters
Clear data on unmount
note
resource module uses Redux global state managment. When you call some action for the first time it will create new item in Redux store with key that is equal to namespace from resourceConfig. So that it is hight recomended to clear you Component data on unmount to keep global store clean.
Change resource configs
It is required to pass initial configuration to resource module, but it is just initial, default config and you can change it.
fetch config
remove config
create config
setData config
tip
Same syntax will be for setLoading, setErrors, setFilters
clear another resource
terminate requests
By default all async actions (fetch, fetchOptions, create, replace, update, remove ) will return Promise with 1 more method cancel. You can use this method to abort HHTP requests