Giter Site home page Giter Site logo

How to use css prop? about glamor HOT 6 CLOSED

threepointone avatar threepointone commented on June 3, 2024
How to use css prop?

from glamor.

Comments (6)

KyleAMathews avatar KyleAMathews commented on June 3, 2024

Oh this is just for style then?

style(css)

from glamor.

threepointone avatar threepointone commented on June 3, 2024

no, you can pass any rule into it

<div css={media(...)}></div>

it also accepts arrays, and wraps 'plain' objects with style, so this works too

<div css={[{color: 'red'}, hover({ color: 'blue'}), media(...)]}></div>

happy to make enhancements if I can make this easier/ simpler.

from glamor.

vdanchenkov avatar vdanchenkov commented on June 3, 2024

Are there any significant performance issues with invoking style() on every render?

from glamor.

threepointone avatar threepointone commented on June 3, 2024

Not really, it barely registers in the perf profile. On my laptop, I can do about 10000 unique styles in under 50ms (in prod mode). As a comparison, all of twitter's css is under 10k styles iirc. And when rerendering, it barely even shows in the perf profile.

Please let me know if do you see any issues, because I keep testing this to be certain.

from glamor.

threepointone avatar threepointone commented on June 3, 2024

For posterity's sake; 2 things you can do if it bothers you much -

  • declare the styles outside render, and spread the object when rendering
  • prerender styles with renderToStatic and feed ids into hydrate while starting up

however, I personally haven't found the need to use these yet.

from glamor.

threepointone avatar threepointone commented on June 3, 2024

closing this, please reopen if I've missed something.

from glamor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.