小编abm*_*bms的帖子

React-Select:如何在加载选项时显示“正在加载...”

我尝试使用“React-Select”作为我的 WordPress 块组件来选择帖子类别。
我想要的是在加载类别时显示“正在加载...”,然后在加载完成时显示类别列表或“未找到类别”。
使用我的代码,它在加载时显示“未找到类别”,然后显示类别列表。

export default class Categories extends Component {
    constructor() {
        super( ...arguments );
        this.state = {cats: []};
    }
    componentDidMount () {
        return apiFetch({path: '/myoriginal-blocks/v1/categories'})
        .then(data => {
            this.setState({cats:data});
        })
    }
    onChangeCategories = newCategories => {
        this.props.setAttributes({ category: newCategories == null ? [] : newCategories });
    }
    render() {
        const { attributes } = this.props;
        const { category } = attributes;
        return (
            <>
                <div>
                    <label>Categories</label>
                    <Select
                        isMulti
                        isClearable
                        placeholder='Search categories...'
                        onChange={ this.onChangeCategories }
                        options={ this.state.cats } …
Run Code Online (Sandbox Code Playgroud)

reactjs wordpress-gutenberg

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

reactjs ×1

wordpress-gutenberg ×1