所以,我想做以下事情,
const [value, setValue] = useState({})
const updateName = (name)
setValue(previousState => {
if (/*check some conditions*/) {
// dont update the state
} else {
return { /* some new state */ }
}
});
Run Code Online (Sandbox Code Playgroud)
无论如何我怎样才能实现它?
我有一个对象,其键可以具有可以是对象、字符串或数组的值。
const obj = {
key1: 'asdf',
key2: {},
key3: ['a','b','c'],
key4: [],
key5: '',
}
Run Code Online (Sandbox Code Playgroud)
我必须过滤所有空的键,即空对象、空数组或空字符串。
typeof除了根据键编写条件然后检查 null之外,还有其他方法吗?