在switch语句中为组件提供回调函数吗?

时间:2019-07-01 19:09:10

标签: reactjs

  

我想要3个组件NewInvoicePane,PostInvoicePane,InvoiceItemsPane   数据发送到父组件Invoice.tsx(getCasePaneComponentClass为   消耗3个组件),无法获取如何编写回调函数   用于保存此组件字段输入,因为它使用switch语句调用

     

NewInvoicePane,PostInvoicePane,InvoiceItemsPane这3个有一些   字段,但没有任何按钮。Invoice.tsx只有要保存的按钮

class Invoice extends React.Component{
state={
        loading: false,
        invoiceData: {},
       };
    getInvoicePanes = (paneNames: string[]) => { 
    let componentToUse = getCasePaneComponentClass(paneName);
                let paneProps = {
                    key: paneName,
                    propertyBundle: propertyBundle,
                    panePropertyBundle: paneName,
                };
                paneData.push({
                    name: paneName,
                    width: paneWidth,
                    height: paneHeight,
                    componentToRender: componentToUse,
                    props: paneProps,
                    product: product
                });
            }
            return paneData;
        };
    }

    PaneUtils.tsx
    export function getCasePaneComponentClass(paneName: string): React.ComponentClass {
    switch (paneName) {
     case "NewInvoicePane":
                return NewInvoicePane;
            case "PostInfoPane":
                return PostInvoicePane;
            case "InvoiceItemsPane":
                return InvoiceItemsPane;
            default:
                return null;
    }

    }

0 个答案:

没有答案