React patterns
Patterns used to manage map state and query/mutate data
useReducer
const [createState, createDispatch] = useReducer(createReducer, {
isCreatingComponent: false, // track if user is creating
showCreateDialog: false, // show initial dialog create form
draftComponent: null, // hold data needed to create record
});createDispatch({ type: "store_draft_component", payload: newComponent });const createReducer = (state, action) => {
switch (action.type) {
case "store_draft_component":
return {
...state, // the other current createState values
draftComponent: action.payload, // data about the component
isCreatingComponent: true, // tell the map code we are creating
};
// ...the rest of the function
Last updated
Was this helpful?