Re: Reset a store to its initial value, doesn't react

Hi, I'm trying to reset a store to its initial value, but when I do so the state doesn't react. The only way I can make it to work is to set each property of the store manually.
// A component with a button to reset the filters
function ThereAreNoEvents(props: ThereAreNoEventsProps) {
return (
<div>
<p>There is nothing here :(</p>
<button
class="btn btn-primary btn-sm mt-4"
onClick={() => {
// Works, but I need to do it for every property
props.setParams('textSearch', '');

// Does not work
props.setParams(structuredClone(defaultSearchParams));
}}
>
Clear filters
</button>
</div>
);
}

export default function EventGroups() {
const [params, setParams] = createStore<SearchParams>(
structuredClone(defaultSearchParams),
);

const eventGroups = createAsync(
() => getEventGroups({ ...params }) as Promise<EventGroupWithEvents[]>,
);

return (.....)
}
// A component with a button to reset the filters
function ThereAreNoEvents(props: ThereAreNoEventsProps) {
return (
<div>
<p>There is nothing here :(</p>
<button
class="btn btn-primary btn-sm mt-4"
onClick={() => {
// Works, but I need to do it for every property
props.setParams('textSearch', '');

// Does not work
props.setParams(structuredClone(defaultSearchParams));
}}
>
Clear filters
</button>
</div>
);
}

export default function EventGroups() {
const [params, setParams] = createStore<SearchParams>(
structuredClone(defaultSearchParams),
);

const eventGroups = createAsync(
() => getEventGroups({ ...params }) as Promise<EventGroupWithEvents[]>,
);

return (.....)
}
2 Replies
REEEEE
REEEEE2mo ago
use reconcile
Cyber Grandma
Cyber GrandmaOP2mo ago
Ohh thank you
Want results from more Discord servers?
Add your server