-1
I have a Componente Button
and the same is found within another componente Main
. My purpose was that by clicking on this componente Button
, it was alternating between other visual components inside the Main.
The Button is like a kind of Component Controller and I would like every click to show a rendered behavior on the different screen, but I’m not able to do it the way I want.
Component Main:
import React, { Component } from 'react';
import './style.css';
import Handlerbutton from './HandlerButton';
class Main extends Component{
render(){
return(
<div className="main" id="main">
<div className="start">
<Handlerbutton />
</div>
</div>
);
}
}
export default Main;
Component Button:
import React, { Component } from 'react';
import './style.css';
import StartAnimatedText from './../StartAnimation';
import Photos from './../../Photos';
class Handlerbutton extends Component {
constructor(props){
super(props);
this.state = {
nextpage: true,
page:0,
component:<StartAnimatedText />,
}
}
handleClick = () => {
const pageNumber = this.state.page;
this.setState({
page: this.state.page += 1,
component: ''
})
//console.log(pageNumber);
if(pageNumber === 0){
this.setState({
component: <Photos />
})
}
else if(pageNumber === 1){
this.setState({
component: 'Outro componente aqui...'
})
}
}
render(){
return (
<div>
{this.state.nextpage && this.state.component}
<button id="btn-start" onClick={this.handleClick}><span>Continuar</span></button>
</div>
);
}
}
export default Handlerbutton;
Rendered component:
Guy puts the code.
– novic
Ready @Virgilionovic
– Dominik
You saw a very basic example?
– novic