I'm new to all mentioned technologies and I'm trying to understand how should I operate in this scenario: I'm trying to fetch a CSV file from an API, once retrieved I want to process it to convert it in a json like object which then I can consume in one of my components. For instance, I want to view this data in a table and perform operations on this data which causes a change of state for that data.
From the documentation there is a transformResponse
field for each endpoint defined which I could use to normalize data needed for my application:
const api = createApi({
baseQuery: fetchBaseQuery({
baseUrl: '/',
}),
tagTypes: ['Post'],
endpoints: (build) => ({
getPost: build.query<Post, number>({
// note: an optional `queryFn` may be used in place of `query`
query: (id) => ({ url: `post/${id}` }),
// Pick out data and prevent nested properties in a hook or selector
transformResponse: (response: { data: Post }) => response.data,
...
This could work but then I would have some confusion about how I can dispatch actions to change this state.
Another solution would use a Redux Toolkit store slice to save the fetched data and also perform the transform operation and dispatch actions.
Any help would be awesome!