React's inline styles allow components to stand on their own by not requiring any external CSS. However HTML's style attributes don't support pseudo selectors like :hover and :active. By using Radium to listen to mouse events we can restore :hover and :active selectors to inline styles.

const { render } = ReactDOM
const rootEl = document.getElementById('root') const Div = Radium(({children}) => {
return (
<div style={style}>
{children}
</div>
);
}); const style = {
backgroundColor: '#07d',
border: 'none',
borderRadius: 4,
color: '#fff',
padding: '5px 20px',
':hover': {
backgroundColor: '#08f'
}
} render(<Div>OK</Div>, rootEl)

So, just need to wrap the compoment in to Radium() method.

[React] Styling a React button component with Radium的更多相关文章

  1. [React] Styling React Components With Aphrodite

    Aphrodite is a library styling React components. You get all the benefits of inline styles (encapsul ...

  2. [React Native] Using the Image component and reusable styles

    Let's take a look at the basics of using React Native's Image component, as well as adding some reus ...

  3. React.Component 与 React.PureComponent(React之性能优化)

    前言 先说说 shouldComponentUpdate 提起React.PureComponent,我们还要从一个生命周期函数 shouldComponentUpdate 说起,从函数名字我们就能看 ...

  4. [React] Refactor a Stateful List Component to a Functional Component with React PowerPlug

    In this lesson we'll look at React PowerPlug's <List /> component by refactoring a normal clas ...

  5. 十九、React UI框架Antd(Ant Design)的使用——及react Antd的使用 button组件 Icon组件 Layout组件 DatePicker日期组件

    一.Antd(Ant Design)的使用:引入全部Css样式 1.1 antd官网: https://ant.design/docs/react/introduce-cn 1.2 React中使用A ...

  6. React.createClass 、React.createElement、Component

    react里面有几个需要区别开的函数 React.createClass .React.createElement.Component 首选看一下在浏览器的下面写法: <div id=" ...

  7. [React] Use React.memo with a Function Component to get PureComponent Behavior

    A new Higher Order Component (HOC) was recently released in React v16.6.0 called React.memo. This be ...

  8. React源码 React.Component

    React中最重要的就是组件,写的更多的组件都是继承至 React.Component .大部分同学可能都会认为 Component 这个base class 给我们提供了各种各样的功能.他帮助我们去 ...

  9. React.Component 和 React.PureComponent 、React.memo 的区别

    一 结论 React.Component 是没有做任何渲染优化的,但凡调用this.setState 就会执行render的刷新操作. React.PureComponent 是继承自Componen ...

随机推荐

  1. UVALive 4043 Ants

    KM   构图求最小权值匹配 保证最小的权值,所连的边一定是能够不相交的. Ants Time Limit: 3000MS   Memory Limit: Unknown   64bit IO For ...

  2. LoadRunner测试下载功能点脚本(方法一)

    性能需求:对系统某页面中,点击下载功能做并发测试,以获取在并发下载文件的情况下系统的性能指标. 备注:页面上点击下载时的文件可以是word.excel.pdf等. 问题1:录制完下载的场景后,发现脚本 ...

  3. C/C++笔试准备(2)

    问题:编辑距离,是指将一个字符串变为另一个字符串,仅可以3种操作:修改一个字符,删除一个字符,插入一个字符.the变成that:删除e,插入a,插入t.20’ 实现编辑距离算法. 解算:利用动态规划的 ...

  4. mysql的锁--行锁,表锁,乐观锁,悲观锁

    一 引言--为什么mysql提供了锁 最近看到了mysql有行锁和表锁两个概念,越想越疑惑.为什么mysql要提供锁机制,而且这种机制不是一个摆设,还有很多人在用.在现代数据库里几乎有事务机制,aci ...

  5. SqlDbType与DbType这间的转换关系

    SqlDbType => DbType SqlDbType.BigInt DbType.Int64 SqlDbType.Binary DbType.Binary SqlDbType.Bit Db ...

  6. 阿里云Centos7使用yum安装MySQL5.6的正确姿势

    阿里云Centos7使用yum安装MySQL5.6 阿里云Centos7使用yum安装MySQL5.6 前言:由于某些不可抗力,我要在自己的阿里云服务器上搭建hadoop+hive+mysql+tom ...

  7. 微软企业库的Cache

    微软企业库的Cache 通常,应用程序可以将那些频繁访问的数据,以及那些需要大量处理时间来创建的数据存储在内存中,从而提高性能.基于微软的企业库,我们的快速创建一个缓存的实现. 新建PrismSamp ...

  8. Is there a complete List of JVM exit codes

    Argument passed to System.exit(x) -> becomes the JVM exit code. Exit code 0 is used to indicate n ...

  9. cf B. Simple Molecules

    http://codeforces.com/contest/344/problem/B #include <cstdio> #include <cstring> using n ...

  10. cf C. Xenia and Weights

    http://codeforces.com/contest/339/problem/C #include <cstdio> #include <cstring> #includ ...