r/reactjs • • Apr 01 '19

Needs Help Beginner's Thread / Easy Questions (April 2019)

March 2019 and February 2019 here.

Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch.

No question is too simple. πŸ€”


πŸ†˜ Want Help with your Code? πŸ†˜

  • Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!

  • Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.

Have a question regarding code / repository organization?

It's most likely answered within this tweet.


New to React?

πŸ†“ Here are great, free resources! πŸ†“


Any ideas/suggestions to improve this thread - feel free to comment here!

34 Upvotes

435 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Apr 23 '19

I completely agree - it would be so much easier to implement a search function this way too. Unfortunately this assignment does not allow us to use any sort of backend use. Which like destroyed 100% of the ideas I had off the bat.

Would you happen to know how I would be able to implement the logic shown here? this is obviously not correct but I am having a tough time trying to figure out how to add additional words in that condition..

theBigFilter(){
 let ohWow = this.state.array.filter(index => index.value.indexOf('goodbye' || 'not me') >-1)
 console.log(ohWow)
}

2

u/timmonsjg Apr 23 '19

Check out includes

Here's a small snippet for you to get some ideas -

searchData(searchTerm) {
   return this.state.data.filter(item => item.toLowerCase().includes(searchTerm.toLowerCase())
}
  // notice the case sensitivity

   // test usage
   const data = ['hello', 'help', 'hell', 'pineapple'];
   searchData('hel'); // ['hello', 'help', 'hell']
   searchData('hell'); // ['hello', 'hell']
   searchData('HE'); // ['hello', 'hell', 'help']

Broadly, you can either have your search update onChange or onSubmit based on your preference.

1

u/Kazcandra Apr 24 '19

https://github.com/kripken/sql.js could be the answer to all your problems :) HTML5 was supposed to come with local database storage, but the implementation of that was halted