I wrote a component with a state chosenGenre and inside it, there is a function that changes the state according to the clicked button.
I would like to take the updated state (which is string) and use it in another component.
This is the component in which the state is declared:
import React, { Component } from 'react';
import Genre from './Genre';
import './GenreSelectPage.css';
import Blues from '../Blues.png';
import Classical from '../Classical.png';
import Country from '../Country.png';
export default class GenreSelectPage extends Component{
state = {
chosenGenre: ""
}
handleClick = (genreName) => {
this.setState({ chosenGenre: genreName });
}
render() {
return(
<div className = "GenreSelectPage">
<h3>Select your desired Kollab Room Genre</h3>
<Genre genrePicture= {Blues} genreClicked = {()=>this.handleClick("Blues")}/>
<Genre genrePicture= {Classical} genreClicked = {()=>this.handleClick("Classical")}/>
<Genre genrePicture= {Country} genreClicked = {()=>this.handleClick("Country")}/>
</div>
)
}
}
And this is the new component for which I want to use the chosenGenre state from GenreSelectPage component :
import React, { Component } from 'react';
import GenreSelectPage from './GenreSelectPage';
export default class InRoomPage extends Component {
render() {
return(
<div className = "InRoomPage">
<p>Welcome to {GenreSelectPage.state.chosenGenre} page</p>
</div>
)
}
}
What should I change inside the:
<p>Welcome to {GenreSelectPage.state.chosenGenre} room !</p>
So it will work?