google / google/site-kit-wp

Refactor codebase to use the `useUIValue` hook.

Open
#13,129 1 comment 0 reactions 1 assignee Claimed by @ankitrox View on GitHub
P2 Type: Enhancement
Dominant language
JavaScript
Stars
1.4k
Forks
383
Avg merge
4d 14h
Merged PRs (30d)
77

Description

## Feature Description

In https://github.com/google/site-kit-wp/issues/12711, we have added `useUIValue` hook. Throughout the codebase, we can replace:

`select( CORE_UI ).getValue()` with `useUIValue` and
`dispatch( CORE_UI ).setValue()` with `setValue` returned by hook.

As per the AC for #12711, we should address this refactor in multiple sub-issues so we don't end up with a single, massive PR.

---------------

_Do not alter or remove anything below. The following sections will be managed by moderators only._

## Acceptance criteria

* All the occurrences of `CORE_UI` data store reads and writes in the codebase are replaced with the usage of `useUIValue` hook calls.

## Implementation Brief

Replace `useSelect( ( select ) => select( CORE_UI ).getValue( key ) )` and `useDispatch( CORE_UI )` + `setValue( key, value )` call sites in component files with `useUIValue( key )`, following the existing pattern in `assets/js/hooks/useUIValue.ts`.

- Read-only usage: `const [ value ] = useUIValue( key )`
- Write-only usage: `const [ , setValue ] = useUIValue( key )`
- Read and write for the same key: `const [ value, setValue ] = useUIValue( key )`
- `dispatch( CORE_UI ).setValues()` (plural, batch sets) call sites are out of scope — no equivalent hook exists.
- Test-file usages of `registry.dispatch( CORE_UI ).setValue()` for state setup remain unchanged — hooks cannot be called outside render context.
- `select( CORE_UI ).getValue()` calls inside a compound `useSelect` alongside other store selectors: split the CORE_UI read into a dedicated `useUIValue` call.

### Test Coverage

- Fix any failing test. No new tests required.

## QA Brief

*

## Changelog entry

*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.