Skip to content

Instantly share code, notes, and snippets.

View hideokamoto's full-sized avatar

Hidetaka Okamoto hideokamoto

View GitHub Profile
// Builderオブジェクトの型
type Builder<Props, Result> = ({} extends Props
? {
build: () => Result;
}
: {}) &
{ [P in keyof Props]-?: SetFunction<Props, P, Result> };
type SetFunction<Props, K extends keyof Props, Result> = (
value: Exclude<Props[K], undefined>
@torounit
torounit / useMeta.js
Last active September 1, 2020 03:28
useState 風味に WordPressのカスタムフィールドを扱うやつ
import { Fragment, useCallback } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
const useMeta = ( key ) => {
const meta = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( 'core/editor' );
const values = getEditedPostAttribute( 'meta' ) || {};
return values[ key ] || '';
}, [] );