-
Notifications
You must be signed in to change notification settings - Fork 143
Pass props and state through render #242
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
I'll discuss the change with my team tomorrow and see if there are any reasons why we hadn't done this already. I know this is something that React hasn't done for whatever reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems pretty sound to me.
The only thing that's a little weird about this is that we still need to use self.props and self.state in other lifecycle methods (some of which already take args and it would be awkward to add these). Does that divergence bother us?
docs/api-reference.md
Outdated
```lua | ||
function MyComponent:render(props, state) | ||
-- props == self.props | ||
-- state == self.state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to add a little bit more explanation of what we're trying to convey here. Maybe a little blurb that says that props and state can be accessed either as arguments or as properties on self?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that, I was just copying Preact's documentation.
This still looks good to me, but I did some digging into why React doesn't do this, and here's what I found: reactjs/rfcs#4 (comment) It's a pretty important point to make! Is it something we're worried about for Roact? Is it something we think we'll need to worry about? I may be missing something, but I think the closing-over-this problem they're talking about applies pretty equivalently to Lua as well as JS |
One more thing to note as a followup: we do also have the same problem already with closing over initial props passed into |
Closes #199
Checklist before submitting:
CHANGELOG.md