Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const onClickClear = (inputType?: 'checkbox' | 'radio', queryProps?: string[]) => () => {
- if (!!queryProps) {
- let params = {};
- let updatedQuery = query;
- if (inputType === 'radio' || (inputType === 'checkbox' && queryProps.length > 1)) {
- if (inputType === 'radio' && queryProps.length === 1) {
- const {publish, ...rest} = query;
- updatedQuery = rest;
- } else {
- params = queryProps.reduce((acc, prop) => ({...acc, [prop]: false}), {});
- updatedQuery = {...query, ...params};
- }
- } else {
- params = {[queryProps[0]]: []};
- updatedQuery = {...query, ...params};
- }
- onUpdateSearch(updatedQuery);
- } else {
- const initialQuery = initialState.query;
- onUpdateSearch(initialQuery);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement