Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ I.E. `tsrcc`
| `rxreducer→` | `redux reducer template` |
| `rxselect→` | `redux selector template` |
| `rxslice→` | `redux slice template` |
| `rxapislice→`| `redux api slice template`|

### PropTypes

Expand Down
37 changes: 37 additions & 0 deletions src/sourceSnippets/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type ReduxMapping = {
reduxReducer: 'rxreducer';
reduxSelector: 'rxselect';
reduxSlice: 'rxslice';
reduxApiSlice: 'rxapislice';
mappingToProps: 'reduxmap';
};

Expand Down Expand Up @@ -88,6 +89,41 @@ const reduxSlice: ReduxSnippet = {
],
};

const reduxApiSlice: ReduxSnippet = {
key: 'reduxApiSlice',
prefix: 'rxapislice',
body: [
"import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'",
'',
`export const ${Placeholders.FileName} = createApi({`,
"baseQuery: fetchBaseQuery({baseUrl: 'http://localhost:3000'}),",
"reducerPath: 'reducerPath',",
"tagTypes: ['Tag'],",
'endpoints: build => ({',
' get: build.query({',
' query: (searchParam) => ({',
' url: `?search=${searchParam}`',
' headers: {',
' }',
' }),',
' }),',
' post: build.mutation({',
' query: payload => ({',
" url: '/',",
" method: 'POST',",
' headers: {',
" 'Content-Type': 'application/json'",
' },',
' body: payload',
' }),',
" invalidatesTags: (result, error) => [{type: 'Tag'}]",
' })',
' })',
'})',
`export const {useGetQuery, usePostMutation} = ${Placeholders.FileName}`,
],
};

const mappingToProps: ReduxSnippet = {
key: 'mappingToProps',
prefix: 'reduxmap',
Expand All @@ -105,5 +141,6 @@ export default [
reduxReducer,
reduxSelector,
reduxSlice,
reduxApiSlice,
mappingToProps,
];