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

Define a theme object:

const theme = {
primary: "#a04ed9"
};

Add provider:

import { ThemeProvider } 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"; const Button = styled.button`
background: ${props => props.theme.primary};
color: white;
font-size: 1rem;
padding: .75rem 2rem;
box-shadow: 3px 5px rgba(,,,0.1);
cursor: pointer;
border: none;
border-radius: 4px;
`; export default props => <Button>{props.children}</Button>;

[React] Theme your application with styled-components and "ThemeProvider"的更多相关文章

  1. styled components草根中文版文档

    1.styled components官网网址 https://www.styled-components.com/docs   以组件的形式来写样式. 1.1安装 yarn add styled-c ...

  2. [React Fundamentals] Using Refs to Access Components

    When you are using React components you need to be able to access specific references to individual ...

  3. [React] React Fundamentals: Using Refs to Access Components

    When you are using React components you need to be able to access specific references to individual ...

  4. [React] Prevent Unnecessary Rerenders of Compound Components using React Context

    Due to the way that React Context Providers work, our current implementation re-renders all our comp ...

  5. The Road to learn React书籍学习笔记(第一章)

    react灵活的生态圈 Small Application Boilerplate: create-react-app Utility: JavaScript ES6 and beyond Styli ...

  6. 使用create react app教程

    This project was bootstrapped with Create React App. Below you will find some information on how to ...

  7. 6周学习计划,攻克JavaScript难关(React/Redux/ES6 etc.)

    作者:余博伦链接:https://zhuanlan.zhihu.com/p/23412169来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 和大家一样,最近我也看了Jo ...

  8. Angular 2 to Angular 4 with Angular Material UI Components

    Download Source - 955.2 KB Content Part 1: Angular2 Setup in Visual Studio 2017, Basic CRUD applicat ...

  9. 推荐 9 个样式化组件的 React UI 库

    简评:喜欢 CSS in JS 吗?本文将介绍一些使用样式组件所构建的 React UI 库,相信你会很感兴趣的. 在 React 社区,对 UI 组件进行样式化的讨论逐步从 CSS 模块到内联 CS ...

随机推荐

  1. angular实现简单的pagination分页组件

    不想使用第三方库,只想使用一个分页器,那么就简单的实现一个,效果如下: 1.使用方式: <custom-pagination *ngIf="enterpriseList.length& ...

  2. 学习NLP:《自然语言处理原理与技术实现(罗刚)》PDF+代码

    自然语言处理技术已经深入我们的日常生活.我们经常用到的搜索引擎就用到了自然语言理解等自然语言处理技术.自然语言处理是一门交叉学科,涉及计算机.数学.语言学等领域的知识. <自然语言处理原理与技术 ...

  3. android 4.4最新官方源代码下载

    国内网络,日夜不休花了一个多月才下载成功android标准源代码,有些开发同人须要.已上传到网盘,分享给大家 微云地址: http://url.cn/PkkSzC 百度云盘地址(更新) http:// ...

  4. socket编程之中的一个:计算机网络基础

    在開始学习网络之前先复习下计算机网络基础吧. 鲁迅说,天下文章一大抄.看你会炒不会炒,基础知识就抄抄书吧. 一 分层模型 1 为什么分层 为了简化网络设计的复杂性.通讯协议採用分层结构.各层协议之间既 ...

  5. js --- return返回值 闭包

    什么是闭包?这就是闭包! 有权访问另一个函数作用域内变量的函数都是闭包.这里 inc 函数访问了构造函数 a 里面的变量 n,所以形成了一个闭包. function a(){ var n = 0; f ...

  6. 谈谈iframe的优缺点

    iframe是一种框架,也是一种很常见的网页嵌入方式,零度今天给大家分析分析它的优缺点. iframe的优点: 1.iframe能够原封不动的把嵌入的网页展现出来. 2.如果有多个网页引用iframe ...

  7. command---调用指定的指令并执行

    command命令调用指定的指令并执行,命令执行时不查询shell函数.command命令只能够执行shell内部的命令. 语法 command(参数) 参数 指令:需要调用的指令及参数. 实例 使用 ...

  8. 00084_Map接口

    1.Map接口概述 通过查看Map接口描述,发现Map接口下的集合与Collection接口下的集合,它们存储数据的形式不同. (1)Collection中的集合,元素是孤立存在的(理解为单身),向集 ...

  9. 洛谷 P2867 [USACO06NOV]大广场Big Square

    P2867 [USACO06NOV]大广场Big Square 题目描述 Farmer John's cows have entered into a competition with Farmer ...

  10. iOS -读书笔记-网络请求

    知道"3次握手"吗?突然想起这个词 什么是3次握手? TCP三次握手/四次挥手详解 这里是3次握手的详解 3次握手就是为了可靠的传送数据,TCP(什么是TCP呢?TCP就是一种可靠 ...