-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
40 lines (37 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import Edit from './edit';
import { BlockEditContextProvider, useBlockEditContext } from './context';
/**
* The `useBlockEditContext` hook provides information about the block this hook is being used in.
* It returns an object with the `name`, `isSelected` state, and the `clientId` of the block.
* It is useful if you want to create custom hooks that need access to the current blocks clientId
* but don't want to rely on the data getting passed in as a parameter.
*
* @return {Object} Block edit context
*/
export { useBlockEditContext };
export default function BlockEdit( props ) {
const { name, isSelected, clientId, __unstableLayoutClassNames } = props;
const context = {
name,
isSelected,
clientId,
__unstableLayoutClassNames,
};
return (
<BlockEditContextProvider
// It is important to return the same object if props haven't
// changed to avoid unnecessary rerenders.
// See https://reactjs.org/docs/context.html#caveats.
value={ useMemo( () => context, Object.values( context ) ) }
>
<Edit { ...props } />
</BlockEditContextProvider>
);
}