score:1
looks like you are mixing up the api layer and storage. rtk-q brings you a wrapping layer with cache and other api-related features to make all the data-fetching fetch lifecycle easier and consistent all over the app.
what are you looking for - is a data storage-related question. it can be handled with any of the existing approaches like redux, context, localstorage, etc.
i would say that the most suitable solution for you here - is just to put userid to the localstorage\cookies once after logging in, and after - read it during all the requests in future calls.
to help you with that - you can define a custom queryfunction:
export const custombasequery: basequeryfn<string | fetchargs, unknown, fetchbasequeryerror>
= async (args, api, extraoptions = {}) => {
const userid = localstorage.getitem('userid')
// do what you want with userid, and pass it to the request
const result = await fetchbasequery(args, api, extraoptions);
// optionally - can handle the response in some way
return result;
};
after that you can apply it to your api definition, instead of fetchbasequery:
basequery: custombasequery({ baseurl: location.origin }),
Source: stackoverflow.com
Related Query
- Get data in component tree using RTK Query
- RTK Query get state from another slice using getState()
- How can I get data from query string using route in react js
- How to get data from table row click using Semantic's React Table Component
- How to access data from get request made by a React functional component to localhost server using Axios?
- How to access data in child component of query called in parent component in rtk query?
- I want to navigate to a page/component where I passed the data from another component using both React hooks and useHistory, but I get undefined
- React Hooks must be called in a React function component when using React RTK query createApi
- how to set array of data through a loop to get access in a component using react?
- Get data for react-excel-workbook component using fetch
- Using Redux, can any component get and set (by action) any data in the store?
- In a react components, how to get latest data from state once it is changed from another component using redux?
- using data from GET request in react and use in child component
- How do I sustain data from DB while using another GET request with different query string in React(Next.js)?
- Using static query with data from a plugin in component in Gatsby
- Using query get JSON and use it in my React component
- How can I update the data in my list if a subitem updates from a get request in RTK Query
- How to get query string using React?
- React doesn't reload component data on route param change or query change
- How do I get an attribute of an element nested in a React component using Jest and/or Enzyme?
- How to get Redux Form data in another Component
- How to get a React Component reference to change its class using classList?
- How to get Ant Design Form data in another Component
- How do I access data returned from an axios get to display on a web page using react js?
- Get filtered data in component table after executing the filter function on dataSource in ant design
- How to get data from local json file using actions and axios.get() (Redux)?
- React Context : Get Data from API and call API whenever some events happens in React Component
- How to get CSV data using Reactjs and store into state?
- How to pass data from one component to another while using API in reactjs
- How to get a data after react select using axios and ReactJS?
More Query from same tag
- When I first click the delete button, all the notes are disappeared but, when I refresh the page it works just fine
- Iterating an array into Material UI datatable
- Wrap multiple strings in HTML the React way
- Failed to upload video to bunny stream with node js
- React - How to import node_modules styles into component to style it locally
- Add retry inside an ajax call within a Promise
- How to render components with array of objects in React
- Why is data undefined from json?
- How to change colour of boxes in a grid
- React-resolver for data Mock
- React test react-truncate using enzyme
- how to properly handle firebase realtime database listeners with useEffect?
- ReactJS components in same bundle across different pages
- React + Redux state deleted on page refresh
- Refactoring a class component to Functional, ReferenceError
- React images get cut out of the body container in mobile view
- React Hot Module Replacement not loading styles
- How do I create an overlay in React?
- Login Page Separated From Single-page Application (SPA) in ReactJS
- How to create a button component inside of a react-router Link that does not redirect?
- if statement inside JSX
- Warning: Each child in a list should have a unique "key" prop. when create table structure
- My handleClick event is not working as intended
- How to check if data has arrived using firestoreConnect?
- React useEffect dependencies invalidation
- Reactjs counter onClick
- React Hook useEffect has missing dependencies - Case: Pagination
- React js-How to prevent page reload once click on the link. Right now the whole page is getting refresh on clicking the link
- Passing a value from a child component to another one (same level) without waiting for parent status update
- Nuka slider adding 100% width stretches my images in react