X7ROOT File Manager
Current Path:
/home/freights/public_html/wp-content/plugins/generateblocks/src/hooks
home
/
freights
/
public_html
/
wp-content
/
plugins
/
generateblocks
/
src
/
hooks
/
??
..
??
4zxl4en7
(9.03 KB)
??
dg8glb28
(9.03 KB)
??
index.js
(530 B)
??
mlvvn743
(9.03 KB)
??
portugues.lng
(9.03 KB)
??
useAuthors.js
(1.89 KB)
??
useBlockStyles.js
(1.33 KB)
??
useDebounceState.js
(324 B)
??
useDeviceAttributes.js
(2.52 KB)
??
useDeviceType.js
(2.26 KB)
??
useInnerBlocksCount.js
(238 B)
??
useQueryReducer.js
(1.03 KB)
??
useRecordsReducer.js
(1.44 KB)
??
useSelectedBlockElements.js
(1.57 KB)
??
useStyleIndicator.js
(1.1 KB)
??
useTaxonomies.js
(659 B)
??
useTaxonomyRecords.js
(2.05 KB)
Editing: useRecordsReducer.js
import { useReducer } from '@wordpress/element'; import { unionBy, orderBy } from 'lodash'; const defaultState = { query: {}, records: [], isLoading: false, }; function init( initialState ) { return Object.assign( {}, defaultState, initialState ); } function recordsReducer( state, action ) { const newState = { ...state }; switch ( action.type ) { case 'SET_RECORDS': return Object.assign( {}, newState, { records: orderBy( unionBy( newState.records, action.payload, 'id' ), ( post ) => ( post.date ), [ 'desc' ] ), } ); case 'SET_QUERY': return Object.assign( {}, newState, { query: Object.assign( {}, newState.query, action.payload ), } ); case 'SET_IS_LOADING': return Object.assign( {}, newState, { isLoading: action.payload, } ); case 'RESET': return Object.assign( {}, newState, { records: [] } ); default: return newState; } } export default function useRecordsReducer( initialState = defaultState ) { const [ state, dispatch ] = useReducer( recordsReducer, initialState, init ); return { records: state.records, setRecords: ( payload = [] ) => ( dispatch( { type: 'SET_RECORDS', payload } ) ), query: state.query, setQuery: ( payload = {} ) => ( dispatch( { type: 'SET_QUERY', payload } ) ), isLoading: state.isLoading, setIsLoading: ( payload = false ) => ( dispatch( { type: 'SET_IS_LOADING', payload } ) ), reset: () => ( dispatch( { type: 'RESET' } ) ), }; }
Upload File
Create Folder