I have the following problem in a React Context:
import * as React from 'react';
export const Context = React.createContext();
function reducer (state, action) {
switch (action.type) {
case 'set': {
SomePackage.parse(action.result, {
options: true
complete: (result) => {
// Result is available here
}
});
}
default: {
throw new Error(`Unhandled action type: ${action.type}`)
}
}
}
export function ContextProvider ({ children }) {
const [state, dispatch] = React.useReducer(reducer, {});
return (
<Context.Provider value={{state, dispatch}}>
{children}
</Context.Provider>
)
}
I can't really find a to return data inside of reducer
from SomePackage.parse
. The data that should be set as the new state is only available inside of the complete
callback and is not returned in any way from SomePackage.parse
Is there an elegant way to return those data?