I have an defined an array as state variable in a functional component
const [MessageResultsFirebase, setMessagesFirebase] = useState<MessageCellPropsFirebase[]>();
I want to filter it using Array.filter function to update the list.
var filterResult: MessageCellPropsFirebase = MessageResultsFirebase?.filter((element, index, array)=>{ return (element.key == snapshot.key); });
but it gives the error "cannot find property filter of undefined". P.S: console.log(MessageResultsFirebase);
works in same context.Please help i am new with these.