question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modal stops working after state update

See original GitHub issue

Description

The Modal component stops working after a state update

Steps to Reproduce

I’ve made a small code snippet to reproduce the problem.

First my dependencies in package.json

"dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "materialize-css": "^1.0.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-materialize": "^3.8.3",
    "react-scripts": "3.4.1"
  }

Code:

import React, {useState} from 'react';
import './App.css';
import 'materialize-css/dist/css/materialize.min.css'
import 'materialize-css'
import {Button, Modal} from 'react-materialize'

function App() {

  const [text, setText] = useState('INITIAL')

  function changeText(){
    setText('AFTER')
  }

  return (    
    <div className="App">
    <p>{text}</p>
    <Button onClick={changeText}>CLICK ME</Button>
     <Modal
      header='Modal Header'
      trigger={<Button>MODAL</Button>}>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
  </Modal>      
    </div>
  );
}
export default App;

Steps to Reproduce

  1. Click on MODAL button, the modal content should be displayed;
  2. Click on CLICK ME button, the text will be updated;
  3. Click on MODAL button again, the modal will not be displayed.

Expected behavior: The modal should be displayed again

Actual behavior: Modal is not displayed

Versions

react-materialize: 3.8.3 materialize-css: 1.0.0 react: 16.13.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alextrasterocommented, Apr 17, 2020

Ok, gonna check it out, thx for the info!

0reactions
tslimacommented, Apr 17, 2020

Before a state update when I click on Modal button the Modal is displayed, then I close it, click again, open again, close again, everything is fine.

After a state update when I click on Modal button, the modal is not displayed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setState doesn't update immediately, what is th best ...
I think your main issue here is that each of your functions (handleChange, addTask, removeTask and handleParam) are mutating the state.
Read more >
Modal won't update its visibility dynamically #617 - GitHub
At first render the modal shows up correctly (based on the initial state) and animates-in as defined. But then, when I press the...
Read more >
Build a simple Modal Component with React - Bits and Pieces
The mechanism of the modal is to show and hide. This is quite easy to achieve in react because of the built-in toggle...
Read more >
<Modal/> Component - React-Bootstrap
Modals are unmounted when closed. Bootstrap only supports one modal window at a time. Nested modals aren't supported, but if you really need...
Read more >
react-native-modal - npm
The modal is controlled by the isModalVisible state variable and it is initially hidden, since its value is false . Pressing the button...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found