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. Android设置定时执行执行一次任务

    private Handler handler = new Handler(){ public void handleMessage(Message msg) { super.handleMessag ...

  2. 初探HTML

    就在今天我抱着试一试的态度稍微看了下HTML5, 尝试着接触一点新知识, 虽然学的并不多, 但是还是异常的兴奋, 感觉有好多东西和之前的不一样了, 包括控件的创建和一些属性的设置等, 总之这些变化与改 ...

  3. JavaScript 公有 私有 静态属性和方法

    1.公有属性和公有方法 这里的 name  age  都是参数传递进去 可以在外面直接实例化调用. 2.私有属性和方法 私有的只能在函数内部使用 作用域的原因 3.静态属性和静态方法 这里我首先 创建 ...

  4. iOS中如何获取image.xcassets中的启动图片

    /** *  获取启动图片 */ +(UIImage *)launchImage{ NSString *imageName=@"LaunchImage-700"; if(iphon ...

  5. 一张图解析如何让img垂直居中对齐

    测试代码: <!DOCTYPE html> <html> <head> <style> .dd { background-color: gray; po ...

  6. Javascript进阶篇——(DOM—节点---获取浏览器窗口可视区域大小+获取网页尺寸)—笔记整理

    浏览器窗口可视区域大小获得浏览器窗口的尺寸(浏览器的视口,不包括工具栏和滚动条)的方法:一.对于IE9+.Chrome.Firefox.Opera 以及 Safari: • window.innerH ...

  7. sqlserver插入datetime

    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

  8. .net 判断日期格式yyyy-MM-dd hh:MM:ss的正则表达式

    加上引用: using System.Text.RegularExpressions; /// <summary> /// 检查字符串是否是日期格式        /// </sum ...

  9. Light oj 1030 二分查找

    1088 - Points in Segments   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  10. Windows下Mysql解压缩版配置安装与卸载

    安装: ①解压Mysql到合适的位置! ②以管理员身份运行命令提示符(cmd),cd C:\Documents and Settings\Administrator\桌面\mysql-5.6.24-w ...