I have an object store in useState, i just want to find out which of this keys have a value of empty and return the key of that emply value
const [projectInfo, setProjectInfo] = useState({
projectName: '',
projectDescription: '',
projectCreator: '',
})
const [error, setError] = useState({})
const handleCheckValidation = () => {
if(!projectInfo.projectName){
setError((prevState) => ({
...prevState,
projectNameError: true,
}))
Thanks!
>Solution :
you can filter the empty value, it will give you array item of empty value,
const isEmptyValue = Object.keys(projectInfo).filter((item) => projectInfo[item] === '')
output: ["projectName", "projectDescription", "projectCreator"]
or if the object is dynamic, and you are getting it through props or api
const [projectInfo, setProjectInfo] = useState(Object.keys(yourObject).filter((item) => yourObject[item] === ''))