用于处理 React 的有用组件和实用程序
用于处理 React 的有用组件和实用程序
npm install react-extrasimport React from 'react';
import {If} from 'react-extras';
const App = props => (
);自动将您的 React.Component 子类方法绑定到实例。请参阅 [autoBind.React() 文档`](https://github.com/sindresorhus/auto-bind#autobindreactself-options)。
条件性地将 CSS 类名连接在一起。
类型: string | object
接受字符串和对象的组合。只包含具有真值的对象键。其他内容将被忽略。
import {classNames} from 'react-extras';
classNames('unicorn', 'rainbow');
//=> 'unicorn rainbow'
classNames({awesome: true, foo: false}, 'unicorn', {rainbow: false});
//=> 'awesome unicorn'
classNames('unicorn', null, undefined, 0, 1, {foo: null});
//=> 'unicorn'
const buttonType = 'main';
classNames({[`button-${buttonType}`]: true});
//=> 'button-main'import {classNames} from 'react-extras';
const Button = props => {
console.log(props);
/*
{
type: 'success',
isBlock: false,
isSmall: true
}
*/
const buttonClass = classNames(
'button',
{
'button-block': props.isBlock,
'button-small': props.isSmall
}
);
console.log(buttonClass);
//=> 'button button-success button-small'
return …;
};###``
如果 condition 属性为 true,则 React 组件会渲染子元素。
请注意,即使在 condition 为 false 时不渲染子元素,它们仍然会被计算。如果您需要在 false 条件下不计算子元素,可以将一个函数传递给 render 属性,该函数返回子元素:
暂无开放 Issues,或尚未同步最近议题。