0
Good night, I have a method that filters an array and arrow the state variable "transactions" with the result of this filter = newArrayTransactions, as you can below.
The child component that passes the value to the filter is a text input that I’m using the onChange method on it. The idea is to dynamically render another component that shows all transactions on the screen, based on this filter that is typed. Works well when I type, but when I delete some letter "it seems" that the filter is not executed.
const handleChangeInput = (value) =>{
const newArrayTransactions = transactions.filter(transaction =>{
return transaction.description.toLowerCase().indexOf(value.toLowerCase())!== -1
})
setTransactions(newArrayTransactions)
Here is the call to the child component by passing the above function
<CreateAndSearch onHandleInput={handleChangeInput}/>
Here is the child component called up
export default function CreateAndSearch({onHandleInput}) {
const handleInput = (e) =>{
onHandleInput(e.target.value)
}
return (
<div className='main-createAndSearch'>
<button className='waves-effect waves-light btn'>
<i className="material-icons left">add</i>
NOVO LANÇAMENTO
</button>
<div className="input-field">
<input id="filtro" type="text" onChange={handleInput}/>
<label hmtlfor="filtro">Filtro</label>
</div>
</div>
)
}