zoukankan      html  css  js  c++  java
  • [React Performance] Use CSS Variables instead of React Context?

    https://epicreact.dev/css-variables/

    Code

    body[data-theme='light'] {
      --colors-primary: deeppink;
      --colors-background: white;
    }
    body[data-theme='dark'] {
      --colors-primary: lightpink;
      --colors-background: black;
    }
    // ThemeProvider:
    const PrimaryText = styled.div(({theme}) => ({
      padding: 20,
      color: theme.colors.primary,
      backgroundColor: theme.colors.background,
    }))
    // CSS Variables:
    const PrimaryText = styled.div({
      padding: 20,
      color: 'var(--colors-primary)',
      backgroundColor: 'var(--colors-background)',
    })
    css variables has much less re-render:
     
     
     
    But usually React is pretty fast, as a user you can diff two version, what is the difference between two version.
     
    From applcation point of view, Context version might be much easier to maintian in the future when app grow.
     
  • 相关阅读:
    CSS样式表
    lianxi!
    传值
    lei!
    3.10
    if else&& stwitch break
    if else 语句
    2016.3.6
    进制转换
    PHP 面向对象的三大特征
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13929650.html
Copyright © 2011-2022 走看看