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

[Experimental] component as props for IconButton #2017

Closed
wants to merge 1 commit into from

Conversation

Lendemor
Copy link
Collaborator

@Lendemor Lendemor commented Oct 22, 2023

Only accept static component because we still need to define the imports during compilation time.

rx.icon_button(icon=rx.icon(tag="add"))

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool! Would it be possible to set a component var in State now?

The private attr in Component makes me a bit nervous, we should add a test to verify that is actually a per-instance value with no bleed over between instances.

@Lendemor
Copy link
Collaborator Author

I did test setting a component as var in the State, sadly it doesn't work, for two reason:

  1. Since a var State value will be determined at runtime, we can't find the import that will be needed (they must be written during compilation time.
  2. Even when the import is present, the Component set inside the state var is not evaluated correctly.

I don't know if it's definitely impossible or if I'm missing some React knowledge to make it work though.

@ElijahAhianyo
Copy link
Collaborator

ElijahAhianyo commented Nov 2, 2023

I did test setting a component as var in the State, sadly it doesn't work, for two reason:

  1. Since a var State value will be determined at runtime, we can't find the import that will be needed (they must be written during compilation time.
  2. Even when the import is present, the Component set inside the state var is not evaluated correctly.

I don't know if it's definitely impossible or if I'm missing some React knowledge to make it work though.

I havent thought this well through but perhaps we can construct the imports dynamically at runtime using dynamic imports and since we know the component we should be able to extract the import paths. A problem I see may be constructing the JSX

@Lendemor Lendemor mentioned this pull request Nov 3, 2023
@Lendemor
Copy link
Collaborator Author

Lendemor commented Nov 3, 2023

I did test setting a component as var in the State, sadly it doesn't work, for two reason:

  1. Since a var State value will be determined at runtime, we can't find the import that will be needed (they must be written during compilation time.
  2. Even when the import is present, the Component set inside the state var is not evaluated correctly.

I don't know if it's definitely impossible or if I'm missing some React knowledge to make it work though.

I havent thought this well through but perhaps we can construct the imports dynamically at runtime using dynamic imports and since we know the component we should be able to extract the import paths. A problem I see may be constructing the JSX

This might be possible, though I see this as a separate PR later on that we can add.
Constructing dynamic import should not be too hard, but constructing the React component from a state value might be a tad more complicated.

I'm closing this PR since #2124 has the proper implementation of this feature.

@Lendemor Lendemor closed this Nov 3, 2023
@picklelo picklelo deleted the lendemor/fix_icon_button branch January 30, 2024 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants