Skip to content
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

Create a Phosphor icons array, which can be later on accessed by index in JSX #26

Closed
pMichaell opened this issue May 14, 2022 · 5 comments
Labels
question Further information is requested

Comments

@pMichaell
Copy link

Hi I'm creating a Slider Component in which I'd like to render some content (phosphor icon included). Slider hook, which I've created, gives me access to the current index at which the slider points. Would it be possible to render an icon by referencing it from icons array with current slider index? I've tried it already, but types do not match Type 'ForwardRefExoticComponent<IconProps & RefAttributes>' is not assignable to type 'ReactNode' . Thank you for your response.

@rektdeckard
Copy link
Member

rektdeckard commented May 15, 2022

Icons have the type ForwardRefExoticComponent because they are forwardRefs and allow you to pass a ref to the rendered SVG DOM node if you need to. I'm not sure I understand your question. It's perfectly possible to render icons from an array:

const iconReferences = [House, Sparkle, Sunglasses];
const iconComponents = [<House />, <Sparkle />, <Sunglasses />];

return (
  <div>
    {iconReferences.map((Icon, i) => <Icon key={i} />)}
    {iconComponents} 
  </div>
);

@rektdeckard rektdeckard added the question Further information is requested label May 15, 2022
@pMichaell
Copy link
Author

Exactly, what I've been looking for, thank you.

@emekaelo
Copy link

So glad I found this, this definitely needs to be included in the readme

@rektdeckard
Copy link
Member

@emekaelo it is...in React's docs. I don't think we need to clarify this difference between a Component and a Node, as it's a fundamental React concept.

@emekaelo
Copy link

@emekaelo it is...in React's docs. I don't think we need to clarify this difference between a Component and a Node, as it's a fundamental React concept.

Alright thanks. I'm just a newbie building a react project in a rush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants