Last active
November 18, 2020 05:19
-
-
Save myogeshchavan97/cfe02f9b162be2d1ff2490558a96cb45 to your computer and use it in GitHub Desktop.
Main component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
class Main extends React.Component { | |
state = { | |
selectedIndex: 0 | |
}; | |
setSelectedIndex = (index) => { | |
this.setState({ | |
selectedIndex: index | |
}); | |
}; | |
renderNav = () => { | |
return ( | |
<div className="links"> | |
{this.props.data.map((item, index) => ( | |
<a | |
key={index} | |
href="/#" | |
className="link" | |
onClick={() => this.setSelectedIndex(index)} | |
> | |
{item.label} | |
</a> | |
))} | |
</div> | |
); | |
}; | |
renderContent = () => { | |
const { selectedIndex } = this.state; | |
return <div>{this.props.data[selectedIndex].content}</div>; | |
}; | |
render() { | |
return ( | |
<React.Fragment> | |
<header>{this.renderNav()}</header> | |
<main>{this.renderContent()}</main> | |
</React.Fragment> | |
); | |
} | |
} | |
export default Main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment