我正在做树结构。
我需要添加数据并想要删除、编辑和搜索
当我在该数据存储新变量之前将新数据推入数组时,我遇到了一个错误
TypeError: treeData.push is not a function
如何将该数据设置到新的变量中以及如何推送数组......
添加.js 文件:
import React, {
useState
} from 'react';
import {
TextField
} from '@fluentui/react/lib/TextField';
import {
DefaultButton,
PrimaryButton,
Stack,
IStackTokens
} from '@fluentui/react';
import './styles.css'
const TextFieldBasicExample = (props) => {
const [newItemValue, setNewItemValue] = useState({
title: ''
});
console.log('onchange', newItemValue);
const handleChange = (e) => {
setNewItemValue({
[e.target.name]: e.target.value,
});
}
const _insert = (event) => {
console.log('onclick', newItemValue);
props.callback(newItemValue);
// setNewItem({
// [event.target.name]:''
// })
}
return ( <
Stack horizontal >
<
Stack className = "add-inp" >
<
TextField label = "Add Item"
name = "title"
onChange = {
handleChange
}
/> <
span id = "error_name" > < /span> <
PrimaryButton text = "Add"
className = "add-btn"
onClick = {
_insert
}
/>
<
/Stack> <
/Stack>
);
};
export default TextFieldBasicExample
芜湖不芜
慕无忌1623718
相关分类