Modal stops working after state update
See original GitHub issueDescription
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
- Click on MODAL button, the modal content should be displayed;
- Click on CLICK ME button, the text will be updated;
- 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:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Ok, gonna check it out, thx for the info!
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.