Estou lendo um livro chamado "The Road to Learn React'' para me aprofundar melhor no assunto e no mesmo mostra como se cria um search filter. Contudo, eu não consigo realizar o procedimento utilizando arrow function, como mostrado abaixo:
const isSearched = searchTerm => item => item.title.toLowerCase().includes(searchTerm.toLowerCase())
class App extends Component {
list = [
{
title: 'React',
url: 'https://facebook.github.io/react/',
author: 'Jordan Walke',
num_comments: 3,
points: 4,
objectID: 0,
},
{
title: 'Redux',
url: 'https://github.com/reactjs/redux',
author: 'Dan Abramov, Andrew Clark',
num_comments: 2,
points: 5,
objectID: 1,
},
{ title: 'JS',
url: 'https://github.com/reactjs/redux',
author: 'Thales',
num_comments: 2,
points: 5,
objectID: 2,
}
];
constructor(props){
super(props)
this.state = {
lista: this.list,
searchTerm: '',
}
}
onDimiss(id){
this.setState({lista: this.state.lista.filter(item => item.objectID !== id)})
}
onSearchChange(e){
this.setState({searchTerm: e.target.value})
}
render(){
return(
<div>
<form>
<input type="text" onChange={() => this.onSearchChange}/>
</form>
...
Logo, consigo realizar utilizando-se do bind:
const isSearched = searchTerm => item => item.title.toLowerCase().includes(searchTerm.toLowerCase())
class App extends Component {
list = [
{
title: 'React',
url: 'https://facebook.github.io/react/',
author: 'Jordan Walke',
num_comments: 3,
points: 4,
objectID: 0,
},
{
title: 'Redux',
url: 'https://github.com/reactjs/redux',
author: 'Dan Abramov, Andrew Clark',
num_comments: 2,
points: 5,
objectID: 1,
},
{ title: 'JS',
url: 'https://github.com/reactjs/redux',
author: 'Thales',
num_comments: 2,
points: 5,
objectID: 2,
}
];
constructor(props){
super(props)
this.state = {
lista: this.list,
searchTerm: '',
}
this.onSearchChange = this.onSearchChange.bind(this)
}
onDimiss(id){
this.setState({lista: this.state.lista.filter(item => item.objectID !== id)})
}
onSearchChange(e){
this.setState({searchTerm: e.target.value})
}
render(){
return(
<div>
<form>
<input type="text" onChange={this.onSearchChange}/>
</form>
...
Alguém pode me explicar o motivo disso ocorrer?
Desde já, agradeço a atenção!