基于onclick按钮功能循环调用react组件,一旦单击按钮,该状态会将状态设置为true

时间:2020-09-17 04:34:47

标签: reactjs material-ui

我是反应新手,我想根据是否单击了按钮来获取组件,并且一旦组件返回到Ui,我想将按钮状态更改回original(false),所以如果我单击该按钮再次,我应该在上一个组件的下面再次添加一个新组件,这应该继续进行.., 在下面的代码中,我仅能获得一次。

def myfunc(df):

    mask = df.sort_values('Date')\
    .groupby(['ITEM_ID', 'VALUE'])['TYPE']\
    .apply(lambda x: ((x == 'O') & (x.shift(-1) == 'I')) | (x == 'I') & (x.shift(1) == 'O'))
    df = df.loc[~mask]
    return df


while True:
    cur_length = len(df)
    df = myfunc(df)
    new_len = len(df)
    print(cur_length ,new_len)
    if cur_length == new_len:
        break
df

1 个答案:

答案 0 :(得分:0)

您想继续添加组件,我建议使用状态组件:

const Command = () => {
    const component =  <div>
        <Grid container>
            <SomeComponent />
        </Grid>
    </div>;
    
    const [components, setComponents] = useState([]);

    return (
        <Fragment>
            <FormControl>
                <SomeComponent />
                {components.map(component => component)}
                <Button onClick={() => setComponents([...components, component])} variant="contained" color="primary">Add Condition</Button>
            </FormControl>
        </Fragment>
    );
};

export default Command;