-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(#2644): adapt the react children api #2645
base: main
Are you sure you want to change the base?
Conversation
I still have to adjust the tests. |
I think that is relevant too ... https://reactjs.org/docs/react-api.html#reactchildren |
No worries, like mentioned on twitter the |
@@ -99,6 +99,16 @@ describe('Children', () => { | |||
expect(serializeHtml(scratch)).to.equal('<div></div>'); | |||
}); | |||
|
|||
it('should propagate the this context', () => { |
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 is a great start, but I think the commit isn't complete. The test defines a few functions but never calls them anywhere. This will make the test always pass, even against current master and without the changes in this PR.
it('should propagate the this context', () => { | |
it('should propagate this context', () => { | |
const context = {}; | |
const spy = sinon.spy(child => child); // noop | |
const Foo = ({ children }) => { | |
return React.Children.map(children, spy, context); | |
}; | |
render(<Foo>foo</Foo>, scratch); | |
expect(spy.thisValues[0]).to.equal(context); | |
}); |
return toChildArray(toChildArray(children).map(fn)); | ||
const mapFn = (children, fn, context) => { | ||
if (!children) return null; | ||
return toChildArray(children).reduce( |
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 don't generally use reduce(). I'd prefer to use .map(fn.bind(ctx))
for size and perf reasons.
Fixes #2644 .