-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README to the useSetting component (#53162)
* Add a README for the useSetting hook * Tweak the readme to add more detail
- Loading branch information
1 parent
143c5c8
commit b2e5f0d
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/block-editor/src/components/use-setting/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## Use Setting | ||
|
||
`useSetting` is a hook that will retrive the setting for the block instance that's in use. | ||
|
||
It does the lookup of the setting in the following order: | ||
|
||
1. Third parties can provide the settings for the block using the filter `blockEditor.useSetting.before`. | ||
2. If no third parties have provided this setting, then it looks up in the block instance hierachy starting from the current block and working its way upwards to its ancestors. | ||
3. If that doesn't prove to be successful in getting a value, then it falls back to the settings from the block editor store. | ||
4. If none of the above steps prove to be successful, then it's likely to be a deprecated setting and the deprecated setting is used instead. | ||
|
||
## Table of contents | ||
|
||
1. [Development guidelines](#development-guidelines) | ||
|
||
## Development guidelines | ||
|
||
### Usage | ||
|
||
This will fetch the default color palette based on the block instance. | ||
|
||
```jsx | ||
import { useSetting } from '@wordpress/block-editor'; | ||
|
||
const defaultColorPalette = useSetting( 'color.palette.default' ); | ||
``` | ||
|
||
Refer [here](https://github.com/WordPress/gutenberg/blob/HEAD/docs/how-to-guides/curating-the-editor-experience.md?plain=1#L330) in order to understand how the filter mentioned above `blockEditor.useSetting.before` can be used. | ||
|
||
### Props | ||
|
||
This hooks accepts the following props. | ||
|
||
#### `path` | ||
|
||
- **Type:** `String` | ||
- **Default:** `undefined` | ||
|
||
The path to the setting that is to be used for a block. Ex: `typography.fontSizes` |