Skip to content
Advertisement

Check if button is active then get its value to pass down a button

enter image description here

JavaScript

The search button when clicked will redirect you to a google search based on the value from the input field, below is the site for advanced search, when active the link will add an additional link after "https://google.com/search?q=${input}+site%3A${activepage}.com, how do I check if one or many sites are active then pass down its name to url

P/s: code for toggling websites

JavaScript

Advertisement

Answer

You can keep a root level state to gather active links to a state. And pass it to the Input component.

  1. Update your Input component to accept array called “ and update the handleSearch to use OR operation in google search.
JavaScript
  1. Accept another function in WebButton called toggleActiveLink and a string called value which refers to the URL part. Call the function with the value inside handleToggle function.
JavaScript
  1. In the main component you have to create a local state to handle the active links. Create the toggle function as given. It will add the value if it is not there otherwise remove it.
JavaScript

Edit mutli site google search react

Advertisement