Fixed!
in searchBox.js I had the onSearchChange as Searchchange, added the on part at it works now.
I’m Trying to work on the OnSearchChange, but When I go check on my local host no information pops up on the console when I input letters into the search bar, I tried a console.log as well, but The console on localhost wont even read the Console log. I think there may be an error in the communication but i’m pretty new and don’t know how to proceed.enter image description here Anyone have any ideas? Thanks in advance and let me know if there is any other code I should upload.
import React, { Component } from "react";
import CardList from './CardList';
import { robots } from './robots';
import SearchBox from './SearchBox';
import './App.css';
class App extends Component {
constructor() {
super()
this.state = {
robots: robots,
searchfield: ''
}
}
onSearchChange = (event) => {
this.setState({ searchfield: event.target.value })
console.log('Hello? Is this thing on?')
}
render() {
const filteredRobots = this.state.robots.filter(robots =>{
return robots.name.toLowerCase().includes(this.state.searchfield.toLowerCase());
})
return (
<div className='tc'>
<h1 className='f1'>RoboFriends</h1>
<SearchBox onSearchChange={this.onSearchChange}/>
<CardList robots={filteredRobots} />
</div>
);
}
}
export default App;
SearchBox.js
import React from "react";
const SearchBox = ({ searchfield, onSearchChange} ) => {
return (
<div className='pa2'>
<input
className='pa3 ba b--green bg-lightest-blue'
type='search'
placeholder='search robots'
onChange={onSearchChange}
/>
</div>
)
}
export default SearchBox
I imputed names into the search bar but got no response, the Console did not pick up any changes it also did not pick up the console.log. I looked through a few discord chanels, youtube videos and the Zero to Mastery Full stack developer course but got nothing.
It is supposed to filter through the names as the name is inputed into the search bar.
2
Answers
I think It looks like there might be a mismatch between the prop names in the SearchBox component. In App.js, you are passing onSearchChange as a prop to SearchBox, but in SearchBox.js, you are expecting a prop named
onSearchChange
, notonSearchChange
.I think you should also bind the search value to the input element in the SearchBox component.