How to use the useReducer function from react

Find comprehensive JavaScript react.useReducer code examples handpicked from public code repositorys.

38
39
40
41
42
43
44
45
46
47
const setImmersedDebounced = React.useCallback(debounce(setImmersed, 3000), []);
const [subtitlesMenuOpen, , closeSubtitlesMenu, toggleSubtitlesMenu] = useBinaryState(false);
const [infoMenuOpen, , closeInfoMenu, toggleInfoMenu] = useBinaryState(false);
const [videosMenuOpen, , closeVideosMenu, toggleVideosMenu] = useBinaryState(false);
const [error, setError] = React.useState(null);
const [videoState, setVideoState] = React.useReducer(
    (videoState, nextVideoState) => ({ ...videoState, ...nextVideoState }),
    {
        manifest: null,
        stream: null,
fork icon129
star icon1
watch icon0

974
975
976
977
978
979
980
981
982
983
  expandedDirection = _useState4[0],
  setExpandedDirection = _useState4[1];
var _useState5 = react.useState(0),
  openSubmenuCount = _useState5[0],
  setOpenSubmenuCount = _useState5[1];
var _useReducer = react.useReducer(function (c) {
    return c + 1;
  }, 1),
  reposSubmenu = _useReducer[0],
  forceReposSubmenu = _useReducer[1];
fork icon48
star icon881
watch icon6

1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
        };
    });
    return newData;
}, [data, columnsWithSorting, columnsByName]);
var reducer = createReducer();
var _a = React.useReducer(reducer, {
    columns: columnsWithSorting,
    columnsByName: columnsByName,
    originalRows: tableData,
    rows: tableData,
fork icon1
star icon1
watch icon0

105
106
107
108
109
110
111
112
113
114
115
};


function DevOverlay({
  children
}) {
  const [state, dispatch] = React.useReducer(reducer, initialState);
  React.useEffect(() => {
    const gatsbyEvents = window._gatsbyEvents || [];
    window._gatsbyEvents = {
      push: ([channel, event]) => {
fork icon0
star icon0
watch icon1

65
66
67
68
69
70
71
72
73
74
get() {
    return this.proxy;
}
useGet(pathsFunction, options = { deep: false }) {
    // https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
    const [, forceUpdate] = react.useReducer(x => x + 1, 0);
    let paths2observe;
    if (typeof pathsFunction === 'function') {
        const pathGeneratorObject = makePathGeneratorProxy();
        const outputs = pathsFunction(pathGeneratorObject);
fork icon0
star icon0
watch icon0