Managing the visibility of a component in React.js can be achieved using the state of the component. The state of a component in React.js is a built-in object that every component has access to. This object allows us to store the values of properties that belong to a component, and we can access and modify these values as needed.
Here is an example of a simple React component that can be toggled visible or invisible:
```
import React, { Component } from ‘react’;
class MyComponent extends Component { constructor(props) { super(props); this.state = { visible: true }; this.toggleVisibility = this.toggleVisibility.bind(this); }
toggleVisibility() { this.setState({ visible: !this.state.visible }); } render() { return (export default MyComponent;
```
In this example, a piece of state (`visible`) is initialized to `true` in the constructor, and a method (`toggleVisibility`) is defined which toggles the `visible` state between `true` and `false` whenever it is called. This method is bound to `this` in the constructor so it can be used properly in the JSX.
In the `render` method, a conditional (ternary) operator is used to decide whether to render the “Visible Content” `div` or not based on the current value of `visible`. A button is also rendered, and its `onClick` handler is set to the `toggleVisibility` method. The button’s label also dynamically changes based on the `visible` state.