[React] Theme your application with styled-components and "ThemeProvider"

Source: Internet
Author: User

In this styled-components lesson, we set a "primary color" within a UI "theme" object. We make the theme accessible to all of the wrapping our application inside a .

Define a Theme object:

Const Theme = {  "#a04ed9"};

ADD provider:

 from " styled-components " ; Reactdom.render (  <themeprovider theme={theme}>    <app/>  </ThemeProvider>,  document.getElementById ("root"));

Use the theme from props:

Import React from "react"; import styled from "styled-components";ConstButton =Styled.button ' background: ${props=Props.theme.primary};  Color:white; Font-Size:1rem;  padding:. 75rem 2rem; Box-shadow:03px 5px Rgba (0,0,0,0.1);  Cursor:pointer;  Border:none; Border-radius:4px; '; exportdefaultProps = <Button>{props.children}</Button>;

[React] Theme your application with styled-components and "ThemeProvider"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.