This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This closes a gap in compatibility with upstream React. While the current Roact implementation doesn't support refs assigned to non-host components, it also doesn't provide a way for non-host components to forward refs idiomatically as described here: https://reactjs.org/docs/forwarding-refs.html This change introduces an upstream-compatible forwardRef API and loosely adapts some of the upstream tests as well. Checklist before submitting: Add a test to validate that the ref isn't also provided as a member of props Added entry to CHANGELOG.md Added/updated relevant tests Added/updated documentation
- Loading branch information
1 parent
dcbeb36
commit 058e3c6
Showing
7 changed files
with
440 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
local assign = require(script.Parent.assign) | ||
local None = require(script.Parent.None) | ||
local Ref = require(script.Parent.PropMarkers.Ref) | ||
|
||
local config = require(script.Parent.GlobalConfig).get() | ||
|
||
local excludeRef = { | ||
[Ref] = None, | ||
} | ||
|
||
--[[ | ||
Allows forwarding of refs to underlying host components. Accepts a render | ||
callback which accepts props and a ref, and returns an element. | ||
]] | ||
local function forwardRef(render) | ||
if config.typeChecks then | ||
assert(typeof(render) == "function", "Expected arg #1 to be a function") | ||
end | ||
|
||
return function(props) | ||
local ref = props[Ref] | ||
local propsWithoutRef = assign({}, props, excludeRef) | ||
|
||
return render(propsWithoutRef, ref) | ||
end | ||
end | ||
|
||
return forwardRef |
Oops, something went wrong.