I am not very new to React but below code is hard to understand.
const UIContext = React.createContext();
const initialFilter = { ... };
export function UIProvider({ children }) {
const [queryParams, setQueryParamsBase] = useState(initialFilter);
const setQueryParams = useCallback((nextQueryParams) => { // <- my problem is here
setQueryParamsBase((prevQueryParams) => {
... // some operations
return nextQueryParams;
});
}, []);
const value = {
queryParams,
setQueryParamsBase,
setQueryParams,
};
return (
<UIContext.Provider value={value}>
{children}
</UIContext.Provider>
);
}
I know useCallback
but in the above code a variable called nextQueryParams
is passed as a parameter of the callback.
What is that nextQueryParams
? The variable name sounds like related to query params, however I couldn't find what is passed as a parameter to the callback from React documentation.
Please help me if anyone knows this.