React - how to make left-side animated menu

10 points
Created by:

In this short article, we would like to show you how to create animated menu in React.

Below solution shows an animated menu floating from the left side on menu button click event.

Practical example:

// ONLINE-RUNNER:browser;

//Note: Uncomment import lines during working with JSX Compiler.
// import React from 'react';
// import ReactDOM from 'react-dom';

const commonStyle = {
    position: 'fixed',
    left: 0,
    top: 0,
    bottom: 0,
    background: 'silver',
    overflow: 'hidden',
    transition: '0.3s'
const visibleStyle = {
    width: '200px'
const hiddenStyle = {
    width: '0px'

const App = () => {
    const [visible, setVisible] = React.useState(false);
    return (
      <div style={{height: '200px'}}>
        {!visible && <button onClick={() => setVisible(true)}>Show</button>}
        <div style={visible ? visibleStyle : hiddenStyle}>
          <button onClick={() => setVisible(false)}>Hide</button>
            1<br />
            2<br />
            3<br />

const root = document.querySelector('#root');
ReactDOM.render(<App />, root );

Note: with spread syntax (...) we are abe to combine objects that were made with styles objects.


Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.


React - left-side animated menu
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂