Switch does not update when changing original status from undefined
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
<Switch checked={this.props.isChecked} />
When this.props.isChecked is undefined( on initial render), the switch is off. When this.props.isChecked later updates to true
, the switch should be on.
Current Behavior
When initial value is true
or false
, everything works as expected. When initial value = undefined
, later updates do not show
Steps to Reproduce (for bugs)
https://codesandbox.io/s/04w6919x4v
In the sample, both switches should become true
after timeout of 2000. checkedA with initial value of false works, checkedB remains unchecked.
Context
Checked prop should be Boolean or String, but sometimes initial values are undefined until server data arrives. a !!checkedB
resolves the issue, but it can be very confusing.
Your Environment
Tech | Version |
---|---|
Material-UI | v1.0.0-beta.25 |
React | 16.2.0 |
browser | Firefox, Chrome |
etc |
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Xcode 14: Publishing changes from within view updates
A very basic example - same behavior... '[SwiftUI] Publishing changes from within view updates is not allowed, this will cause undefined behavior.' import ......
Read more >Troubleshoot Switch Port and Interface Problems - Cisco
This document describes how to determine why a port or interface experiences problems.
Read more >Angular 2 - View not updating after model changes
I can see from the results of console.log(this.recentDetections[0].macAddress) that the recentDetections object is being updated, but the table in the view ...
Read more >Cannot read property 'status' of undefined · Issue #352 - GitHub
I run into this very error when I run under node 6.9.2 (LTS) but don't see it when I switch to 4.0.0. Is...
Read more >Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined. Undefined means that a variable has been declared but has not been assigned a value....
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 FreeTop 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
Top GitHub Comments
@eleventy The current behavior is the expected behavior. Have a look at #9525 for more detail. However, we miss the following warning:
I was able to get it by applying this simple change to your codesandbox demo:
Fixing the missing warning should be as simple as changing this line: https://github.com/mui-org/material-ui/blob/649ef2e34c10c90788b7506e88958c91f87f924c/src/internal/SwitchBase.js#L123
Thanks @pietrofxq and @eleventy! I have tried doing that but I get the same result. Here’s what I am doing:
Render a TableHead. Inside TableBody, give it a
this.state.userInfo
children. This is initiallynull
.Inside
componentDidMount
, make a fetch request to the server.When that Promise resolves, map the results array to that
userInfo
key in state returning a TableRow with the required values set insideTableCell
. Here, every row contains a boolean which is what theSwitch
should use.Since, the state will be set, shouldn’t the toggle refresh itself again? If I set everything to false, it still doens’t work the way I suppose it should. What do you think?