My Objective is to make a simple open and close menu in React. Im used to vannila javascript where i can use getElementById to get my elements and store them in a variable, and do whatever i want whit them. Now im trying to do that whit react, but its getting a little dificult, i have try to use ref.
So this is my menu, i want to click on the button and hide the menu and show the content, that is my objective.
import React, { Component } from 'react';
import { Grid, Row, Col } from 'react-flexbox-grid';
class Menu extends Component {
render() {
function handleClick(e) {
var mobileContainer = this.refs.mobileContent1;
console.log(mobileContainer);
}
return (
<Grid fluid>
<div className="menuContent">
<Row center="xs">
<Col xs={12}>
<span href="" className="button" onClick={handleClick}>Hello, world!</span>
</Col>
</Row>
</div>
</Grid>
);
}
}
export default Menu;
When i console log mobileContainer i get this is undefined
This is my content component
import React, { Component } from 'react';
import { Grid, Row, Col } from 'react-flexbox-grid';
class MobileContent extends Component {
render() {
return (
<Grid fluid>
<div className="mobileContent" ref="mobileContent1">
<Row center="xs">
<Col xs={12}>
<span className="button">Hello, world!</span>
<span className="close">X</span>
</Col>
</Row>
</div>
</Grid>
);
}
}
export default MobileContent;
Thanks for the Help