-
Notifications
You must be signed in to change notification settings - Fork 143
Setting self.state to something other than a table only fails when calling setState #264
Comments
Digging around a bit, it looks like this is partially related to the logic in Lines 13 to 21 in f55538b
If all of the inputs that we're copying from are empty or nil, then we never even attempt to copy anything to the target and we don't get any errors. After calling init, we assign the result of Lines 319 to 324 in f55538b
If |
I thought self.state = {} was still the recommended way to set the initial state in init()? |
The best practice as of Roact 1.x is to call setState instead of assigning directly. https://roblox.github.io/roact/api-reference/#init (as well as the examples in the "Guide" section of the docs) should be up-to-date with this. I suspect this change hasn't been communicated particularly well, though, so we may want to find more ways to promote the new best practice. All of that said, we should still fix this issue by adding a check in the appropriate place after calling |
Is adding a check just after This condition could happen any time a user reassigns I believe this problem will largely be solved by Luau types once we get them, which will solve this issue in all cases. |
For example, if you set self.state to a string, nothing fails immediately. When you later call self:setState, you get a "table expected, got string" error, but attached to the setState line, which makes it hard to trace what went wrong. (Roact should probably raise an error if self.state is not a table after init().)
The text was updated successfully, but these errors were encountered: