I need to pass a variable between two files, this variable will store data(userId) gotten from file one(fetched from an api) so that I can use the variable as a parameter in an endpoint in file two. I have used redux toolkit to create a global state but I can not figure out how to use reducers(from a third file slice.js) to update the global state to the data gotten from file one . I actually do not know how to go about this at all.
file one : inside this file ,there are buttons rendered dynamically from an api that leads to another page when any of the buttons is clicked. On this other page , there is gonna be some information displayed depending on the id gotten.
const [usersData, setUsersData] = userState([]);
useEffect({
fetchData()
});
export default function FileOne(){
return(
<>
{usersData.map(userData => (
<Link to='/fileTwo'>
<button>{userData.id}</button>
</Link>
)}
</>
)
}
so i have used redux toolkit to create a global variable
slice.js:
import { createSlice } from '@reduxjs/toolkit';
const initialState = {
userId:0
// Your global state properties here (e.g., count: 0, data: [])
};
export const idSlice = createSlice({
name: 'id',
initialState,
reducers: {
getUserId(state){
},
// Reducer functions to update the state (e.g., increment(state) { ... })
},
});
export const { getUserId} = idSlice.actions;
export default idSlice.reducer;
what i need help with is how i'm gonna update userId(the global state)to each user's Id depending on the button clicked inside file one