question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apply `as` in advance

See original GitHub issue

I’m looking to achieve something similar to styled(Component). I really need to find out the types for the props when as is applied.

// imagine this does something fancy or stateful
const MyComponent = (props) => <div {...props}  />;

const Box = createBoxWithAtomsProp(atoms);
const AsBox = (props/*: Calculate Me */) => <Box {...props} as={MyCompent} />

Trying a few things with little success.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TheMightyPenguincommented, Aug 28, 2021

@waynevanson sorry for the delay here, you can solve this by doing something like:

const Button = (props: { text: string } & React.ComponentProps<"button">) => {
  return <button {...props}>{props.text}</button>;
};

const ButtonAsBox = (
  props: React.ComponentProps<typeof Box> & React.ComponentProps<typeof Button>
) => <Box as={Button} {...props} />;

// And then use it like:
< ButtonAsBox background="yellow" padding="extraLarge" text="Hello" />

The important part here is using React.ComponentProps to get the props from both Box and the other component you’re interested in!

Also, a useBox hook will be coming soon that will make using the Box props in other components a bit easier.

I’d also recommend using Box directly of that other component if you’re in control of that, as Box is meant to be used as a styling primitive inside of our apps, I recommend reading the FAQ section in our READMe (just added ✨).

Closing this @waynevanson, please feel free to reopen if this didn’t help.

0reactions
waynevansoncommented, Sep 29, 2021

Great work, I’ve got nothing more to add!

Read more comments on GitHub >

github_iconTop Results From Across the Web

apply in advance to | English examples in context - Ludwig
High quality example sentences with “apply in advance to” in context from reliable sources - Ludwig is the linguistic search engine that helps...
Read more >
Advance Auto Parts Careers
A World In Motion. Don't miss your next opportunity. Advance Auto Parts' Talent Network sends career alerts for new positions that match your...
Read more >
I-131, Application for Travel Document - USCIS
Use this form to apply for a re-entry permit, refugee travel document, TPS travel authorization document, advance parole travel document ...
Read more >
Advance Application Definition | Law Insider
Advance Application means a writing or electronic transmission, in such form or forms as shall be specified by the Bank from time to...
Read more >
Advance America: Easy and fast online cash advances, cash ...
Advance America is here to help you with easy online cash advances, fast cash loans and more. Apply online now or visit any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found