Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS toLowerCase is not a function

I am doing a comparison by converting my text to lowercase and comparing its index to -1, in order to have some value to the particular field in ReactJS, but I am getting this error in JavaScript console:

Uncaught TypeError: props.filterText.toLowerCase is not a function

var props = this.props;
var rows = this.props.episodes
    .filter(function(episode){
        return episode.title.toLowerCase().indexOf(props.filterText.toLowerCase()) > -1;
    })
    .map(function(episode){
       return <EpisodeRow key={episode.title} episode={episode}/>
    });
like image 338
MaxWorld Avatar asked Feb 07 '16 00:02

MaxWorld


1 Answers

Looks like Chris's comment is the correct answer:

If title is a string, use toString() before toLowerCase():

return episode.title.toString().toLowerCase().indexOf(props.filterText.toString().toLowerCase()) > -1;
like image 106
ThePatelGuy Avatar answered Nov 09 '22 08:11

ThePatelGuy