-
Notifications
You must be signed in to change notification settings - Fork 48
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
How to pass function as child? #71
Comments
@goto-bus-stop @substack is passing a function as a child possible at all? |
I don't think so. it might work if you pass it as the |
@goto-bus-stop ah okay, thank you for you reply! That's a bummer, I've been looking around for a JSX alternative because I don't like the magic, seems that there is no replacement out there yet. |
This isn't restricted to apollo btw. I've seen react components accept functions before. Just tested with GatsbyJS too: import React from 'react';
import { StaticQuery, graphql } from 'gatsby';
import hyperx from 'hyperx';
const hx = hyperx(React.createElement);
export default ({ children }) => hx`
<${StaticQuery}
query=${graphql`
{
site {
siteMetadata {
title
}
}
}
`}
render=${() => {}}
/>
`; Interestingly enough this gives a different error though: |
Funny thing is the above is a pretty bad example, I would say the following using just import { createElement } from 'react';
import { StaticQuery, graphql } from 'gatsby';
export default ({ children }) => createElement(
StaticQuery,
{
query: graphql`
{
site {
siteMetadata {
title
}
}
}
`,
render: () => {},
}
); Though mixing |
We could probably loosen the type check to allow function children, but I also agree that using createelement is nicer. I'd alias it to something like |
Hmm loosening the type check could be desirable because I'm not sure if in all cases |
👋 hi, wondering how to pass a function to a component. Trying to use the
Query
component fromreact-apollo
.Returns:
The text was updated successfully, but these errors were encountered: