How to use the use-immer.useImmerReducer function in use-immer

To help you get started, we’ve selected a few use-immer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uyuni-project / uyuni / web / html / src / manager / content-management / shared / components / panels / sources / channels / channels-selection.js View on Github external
const ChannelsSelection = (props: PropsType) => {
  const {fetchChannelsTree, isChannelsTreeLoaded,channelsTree }: UseChannelsType = useChannelsTreeApi();
  const {fetchMandatoryChannelsByChannelIds, isDependencyDataLoaded, requiredChannelsResult}= useMandatoryChannelsApi();
  const [state, dispatchChannelsSelection] : [StateChannelsSelectionType, (ActionChannelsSelectionType) => void]
    = useImmerReducer(
    (draft, action) => reducerChannelsSelection(draft, action, channelsTree, requiredChannelsResult),
    initialStateChannelsSelection(props.initialSelectedIds),
  );

  const isAllApiDataLoaded = isChannelsTreeLoaded && isDependencyDataLoaded;

  useEffect(() => {
    fetchChannelsTree()
      .then((channelsTree: ChannelsTreeType) => {
        fetchMandatoryChannelsByChannelIds({channels: Object.values(channelsTree.channelsById)});
      })
  }, [])

  useEffect(() => {
    // set lead base channel as first and notify
    const sortedSelectedChannelsId = state.selectedChannelsIds
github datenguide / datenguide / src / pages / detail.js View on Github external
const Detail = ({ initialStatistics, initialRegions, initialError }) => {
  const classes = useStyles()

  const [state, dispatch] = useImmerReducer(reducer, {
    regions: initialRegions,
    statistics: initialStatistics,
    error: initialError
  })

  const { regions, statistics, error } = state

  return (
github mashabow / bezier-smoothness / src / store.tsx View on Github external
export const Provider: React.FC = ({ children }) => {
  const [state, dispatch] = useImmerReducer(reducer, initialState);
  return (
    {children}
  );
};

use-immer

Use immer with React hooks

MIT
Latest version published 5 months ago

Package Health Score

78 / 100
Full package analysis