Mam problem z wyszukiwarką mianowicie nie działa jak należy. Gdy wpisuję w input jakiś tekst to cos tam wyszukuje, ale gdy usunę to znikają wszystkie elementy. Prosze o pomoc.
State zawiera nazwy pobrane z api
const courseReducer = (state, action) => {
switch (action.type) {
case 'SEARCH':
return state.filter(task => task.name.toLocaleLowerCase().includes(action.searchText))
}
}
const [state, dispatch] = useReducer(courseReducer, [])
Form.js
const Form = () => {
const { dispatch, state } = useContext(DataContext)
const [text, setText] = useState('')
const handleInput = event => {
setText(event.target.value)
const searchText = text.toLocaleLowerCase();
dispatch({ type: 'SEARCH', searchText })
}
return (
<input type="text" value={text} onChange={handleInput} />
}