TypeError:Object(...)不是函数React js

时间:2019-12-31 06:22:22

标签: javascript reactjs react-redux react-hooks es6-promise

我想使用带有返回类型[ <TextView android:id="@+id/back_button" style="@style/Widget.AppCompat.Button.Borderless" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="72dp" android:background="@android:color/red" android:paddingTop="20dp" android:paddingBottom="20dp" android:text="This is a button" android:clickable="true" android:focusable="true" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> ]的React.memo创建泛型函数。现在,这样做会引发“ list,listItemsTypeError(...)不是函数”错误,我不知道为什么。我需要反馈和建议来解决此问题。我正在使用最新版本“ Object”:“ ^ 16.12.0”,“ react”:“ ^ 16.12.0”,

通用函数

react-dom

主要组件

   import React, { memo, useState, useEffect, useRef } from 'react';
import Card from '@material-ui/core/Card';

export const useGeneric = React.memo(({
    list = [],
    handleClick,
    deleteWorkflow,
}) => {

    const [items, setItems] = useState([]);
    const [listItems, setListItems] = useState([]);

    function setImgIcon(name) {
        switch (name.toUpperCase()) {

        }

    }

    function display() {
        console.log('newItemList', list);
        setItems(list);
        let listItems = list.map(val => (
            <li
                className='block-list-workflow'
                key={val.workflowId}
                data-id={val.workflowId}
                id='2'
            >
                <Card className='wf-Card'>

                </Card>
            </li>
        ));
        setListItems(listItems);
    }

    useEffect(() => {
        display();
        return () => { };
    }, []);

    return [items, listItems];
    });

1 个答案:

答案 0 :(得分:0)

您可以尝试以以下主要形式使用记事吗:

    const UseGeneric  = memo((list = [],handleClick,deleteWorkflow) => { 
                   //Your memo codes
    }

并使用通用Cmp。喜欢

    <UseGeneric
        list= {//your list}
        handleClick = { //your click}
        deleteWorkflow = { // your flow}
    />