Skip to content

Commit d4eab60

Browse files
committed
fix: Use data hooks for FAQ heading synchronization
Updates the `useSyncQuestionHeadingLevels` hook to leverage `@wordpress/data`'s `useSelect` and `useDispatch` for accessing block editor state and actions. This removes the need to pass the `blockEditor` object as a prop, improving the hook's encapsulation and aligning with modern WordPress block editor development patterns.
1 parent 2f1d1f8 commit d4eab60

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

src/faq/edit.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@ function syncQuestionHeadingLevels(
7272
} );
7373
}
7474

75-
function useSyncQuestionHeadingLevels(
76-
clientId,
77-
headingLevel,
78-
isAccordion,
79-
blockEditor
80-
) {
81-
const { getBlocksByClientId, updateBlockAttributes } = blockEditor;
75+
function useSyncQuestionHeadingLevels( clientId, headingLevel, isAccordion ) {
76+
const { getBlocksByClientId } = useSelect(
77+
( select ) => select( blockEditorStore ),
78+
[]
79+
);
80+
const { updateBlockAttributes } = useDispatch( blockEditorStore );
8281

8382
useLayoutEffect( () => {
8483
syncQuestionHeadingLevels( clientId, headingLevel, isAccordion, {
@@ -111,12 +110,7 @@ export default function Edit( { clientId, attributes, setAttributes } ) {
111110
);
112111
const { getBlocks, getBlocksByClientId } = blockEditor;
113112

114-
useSyncQuestionHeadingLevels(
115-
clientId,
116-
headingLevel,
117-
isAccordion,
118-
blockEditor
119-
);
113+
useSyncQuestionHeadingLevels( clientId, headingLevel, isAccordion );
120114

121115
// Synchronize isAccordion attribute to all child blocks
122116
useEffect( () => {

0 commit comments

Comments
 (0)