Skip to content

Commit

Permalink
Implement rerender with useReducer
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Nov 20, 2024
1 parent 04db6fd commit d3cafb4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/slot-fill/bubbles-virtually/fill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useObservableValue } from '@wordpress/compose';
import {
useContext,
useReducer,
useRef,
useEffect,
createPortal,
Expand All @@ -14,13 +15,12 @@ import {
*/
import SlotFillContext from './slot-fill-context';
import StyleProvider from '../../style-provider';
import useForceUpdate from '../use-force-update';
import type { FillComponentProps } from '../types';

export default function Fill( { name, children }: FillComponentProps ) {
const registry = useContext( SlotFillContext );
const slot = useObservableValue( registry.slots, name );
const rerender = useForceUpdate();
const [ , rerender ] = useReducer( () => [], [] );
const ref = useRef( { rerender } );

useEffect( () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/slot-fill/slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ReactElement, ReactNode, Key } from 'react';
import {
useContext,
useEffect,
useReducer,
useRef,
Children,
cloneElement,
Expand All @@ -20,7 +21,6 @@ import {
*/
import SlotFillContext from './context';
import type { SlotComponentProps } from './types';
import useForceUpdate from './use-force-update';

/**
* Whether the argument is a function.
Expand All @@ -34,7 +34,7 @@ function isFunction( maybeFunc: any ): maybeFunc is Function {

function Slot( props: Omit< SlotComponentProps, 'bubblesVirtually' > ) {
const registry = useContext( SlotFillContext );
const rerender = useForceUpdate();
const [ , rerender ] = useReducer( () => [], [] );
const ref = useRef( { rerender } );

const { name, children, fillProps = {} } = props;
Expand Down
9 changes: 0 additions & 9 deletions packages/components/src/slot-fill/use-force-update.ts

This file was deleted.

0 comments on commit d3cafb4

Please sign in to comment.