🪴 notes

Search

Search IconIcon to open search

redux state outside a component

Published May 5, 2023 Last updated May 5, 2023 Edit Source

docs

When using rtk query, you might want to access state from outside a react component. This can be done by:

1
2
const result = api.endpoints.getPosts.select()(state);
const { data, status, error } = result;

api above is created with createApi. The state is from store.getState(), more.