Pass state from a JSX NavBar to a JSX Map in react

So I can't figure out how to use React to pass the state of my navBar to my map. I get the date from my nav bar and I need to use it in my map to display stuff only if the date matches.

class NavSearchBar extends Component {

    constructor(){
        super();
        this.state = {
            startDate: moment().startOf('month'),
            endDate: moment().startOf('month'), 
    }//these get updated somewhere else in the code
    ...

and

class MyMap extends Component {
   OnEachCountry = (country, layer) => { // loops thru every country
        const country_name = country.properties.NAME; // name of country
        country.properties.reported_incidents = 0; // reported incidents
        for(var tweet2 = 0; tweet2<tweet_loc.length;tweet2++){ // loops thru tweet list
            var Location_Name = JSON.stringify(tweet_loc[tweet2].user.location);
            if(Location_Name.includes(country.properties.NAME) || 
               Location_Name.includes(country.properties.ADM0_A3)){ 
                country.properties.reported_incidents++;
              // in this for loop I want to check if its between the dates too so like 
              //nav.state.startDate
            }
        }
}

So I'm pretty new to React, Javascript, css, jsonfiles, just starting with this project. So where the loop is I want to grab something like Navbar.state.startDate, so I can compare it against the dates in my map file.



Read more here: https://stackoverflow.com/questions/64902566/pass-state-from-a-jsx-navbar-to-a-jsx-map-in-react

Content Attribution

This content was originally published by Gex at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: