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

Preact / Emotion / TypeScript example #117

Open
antoniobrandao opened this issue Apr 11, 2023 · 1 comment
Open

Preact / Emotion / TypeScript example #117

antoniobrandao opened this issue Apr 11, 2023 · 1 comment

Comments

@antoniobrandao
Copy link

antoniobrandao commented Apr 11, 2023

This is not a bug report, more of a request. Will a Preact + Emotion + TypeScript be available sometime?

I'm hoping it would be helpful as I'm trying to set one up, but struggling to get the tw attribute to work on elements.

Although I get no errors, this:
<div tw="underline">Text</div>
Renders like this:
<div css="[object Object]" data-tw="underline">Text</div>

I created a slimmed-down repo if you would like to check the config:
https://github.com/antoniobrandao/preact-twin-typescript-test

Using tw in the styled element works fine but not as a custom attribute:

import tw, { styled } from 'twin.macro'

const StyledElement = styled.p(() => [
  tw`underline`,
])

const App: FunctionalComponent = () => {
  return (
    <>
      <StyledElement>
        Underline styled element (this works, text renders underlined)
      </StyledElement>
      <br />
      <div tw='underline'>
        Div with with tw property 'underline' (doesn't work, text doesn't renders underlined)
      </div>
    </>
  );
};

Thank you for the great work on twin.macro, I'm a proud sponsor

@antoniobrandao antoniobrandao changed the title Preact example with TypeScript Preact / Emotion / TypeScript example Apr 11, 2023
@ben-rogerson
Copy link
Owner

Will a Preact + Emotion + TypeScript be available sometime?

I've had issues with previous techniques that add the css prop automatically and I've looked through many issues for the answer. This is the main reason I haven't released a typescript example.

The only way to use the css prop I've found is to add the pragma in the file:

/** @jsx jsx */
import { jsx } from "@emotion/react";

I'll keep this open as someone may be able to help here.

Thanks for the sponsor!

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

No branches or pull requests

2 participants