English 中文(简体)
• 如何在改写型呼号时适当确定部件状态
原标题:How to properly set component state during onChange call in React Typescript

我有一个组成部分的检查箱组,在点击检查箱时,其功能叫上Change。 我怎么能够向Change(Change)发出这一呼吁时更新选定的Values的状况?

export const CheckboxWindow: React.FC<Props> = props => {
    const [selectedValues, setSelectedValues] = React.useState<string[]>([]);

    return (
        <Window>     
            <CheckboxGroup
                onChange={(checked, value) => {
                    if (checked && !selectedValues.includes(value)) {
                        this.setState({
                            selectedValues: [...this.state.selectedValues, value],
                        });
                    } else if (!checked && selectedValues.includes(value)) {
                        setSelectedValues(selectedValues.filter(val => val != value));
                    }
                }}
            />
        </Window>
    );
};

我正在犯错误:

Object is possibly undefined for this.setState and this.state .

当选 然而,如果看似可收取罚款,则其他数值。

最佳回答

你们正在混合班级和职能部分。 由于你正在使用一个功能部分,你不应使用<条码>、关键词或<条码>。 事实上,从<代码>使用国家<>代码/代码>返回的阵列中的第二个项目是,你将如何在功能部分中说明最新情况:

if (checked && !selectedValues.includes(value)) {
    setSelectedValues(prev => [...prev, value])
}
问题回答

这是职能部分,没有规定国家。





相关问题
Flex application layers

I m new to Flex and I want to separate app tiers/components as much as possible. So I have three mxmls: X.mxml which has a datagrid with students Y.mxml which must be able to tell which student is ...

How do i use TLBIMP.EXE?

I ve found it in my visual studio folder, but when i open it it simply loads and closes instantly. is that the right way to reach to it s functionalities ?

Where should I begin when building a component?

I am looking to build my own component and have no idea where to begin. I have some Delphi books but they are old and outdated, and am looking for some recommendations on tutorials/books to help me ...

Freeware ZIP component for Delphi 2010/Delphi XE?

Do you know any free component, compatible with Delphi 2010 or XE to manage ZIP archives (actually, only reading archive contents and extracting files required)? Please no betas. I thought about ...

Sharing components in .NET platform

I have an e-commerce website that is already up and running for some time. It s built on .NET 3.5. So far, so good. The "problem" is that now I need to start sharing functionality (products list, ...

array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

热门标签