Skip to content

Commit

Permalink
Style Book: Avoid state/effect combo when generating values (#66446)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ramonjd <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent 2036d7e commit 22a3bf5
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions packages/edit-site/src/components/style-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ import {
import { privateApis as editorPrivateApis } from '@wordpress/editor';
import { useSelect } from '@wordpress/data';
import { useResizeObserver } from '@wordpress/compose';
import {
useMemo,
useState,
memo,
useContext,
useEffect,
} from '@wordpress/element';
import { useMemo, useState, memo, useContext } from '@wordpress/element';
import { ENTER, SPACE } from '@wordpress/keycodes';

/**
Expand Down Expand Up @@ -148,7 +142,7 @@ function StyleBook( {
const [ textColor ] = useGlobalStyle( 'color.text' );
const [ backgroundColor ] = useGlobalStyle( 'color.background' );
const colors = useMultiOriginPalettes();
const [ examples, setExamples ] = useState( () => getExamples( colors ) );
const examples = useMemo( () => getExamples( colors ), [ colors ] );
const tabs = useMemo(
() =>
getTopLevelStyleBookCategories().filter( ( category ) =>
Expand All @@ -159,11 +153,6 @@ function StyleBook( {
[ examples ]
);

// Ensure color examples are kept in sync with Global Styles palette changes.
useEffect( () => {
setExamples( getExamples( colors ) );
}, [ colors ] );

const { base: baseConfig } = useContext( GlobalStylesContext );

const mergedConfig = useMemo( () => {
Expand Down

0 comments on commit 22a3bf5

Please sign in to comment.