SelectControl and categories/tags

Question

I’m trying to give users the ability to form a custom query via categories and tags, in a dynamic block. I’m assuming I can do this via multiple SelectControls (one for each taxonomy). This is what I have so far:

export default function Edit( { className, attributes, setAttributes } ) {

    const categories = useSelect(select =>
        select('core').getEntityRecords('taxonomy', 'category')
    );

    return (
    
            <InspectorControls>
                <PanelBody title="Post selection" >
                    <PanelRow>
                        <SelectControl
                            multiple
                            label={ __( 'Categories' ) }
                            help={ __( 'Select one or more categories' ) }
                            options={categories.map(({id, name}) => ({label: name, value: id}))}
                        />
                    </PanelRow>
                </PanelBody>
            </InspectorControls>
        
    );
}

It’s predictably not working (getting minified react error #130). I’m a little sketchy on the use of HOCs and state management. If anyone can point me in the right direction, or suggest a better way, I’d appreciate it.

0
jshwlkr 2 years 2020-10-23T12:10:28-05:00 0 Answers 18 views 0

Leave an answer

Browse
Browse