Skip to content

Instantly share code, notes, and snippets.

@myogeshchavan97
Last active November 18, 2020 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myogeshchavan97/cfe02f9b162be2d1ff2490558a96cb45 to your computer and use it in GitHub Desktop.
Save myogeshchavan97/cfe02f9b162be2d1ff2490558a96cb45 to your computer and use it in GitHub Desktop.
Main component
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