Rate

Rate component.

When To Use#

  • Show evaluation.

  • A quick rating operation on something.

Examples

The simplest usage.

import { Rate } from 'antd';

ReactDOM.render(<Rate />, mountNode);
3 stars

Add copywriting in rate components.

import { Rate } from 'antd';

class Rater extends React.Component {
  state = {
    value: 3,
    count: null,
  }
  handleChange = (value) => {
    this.setState({ value });
  }
  render() {
    const { value } = this.state;
    return (
      <span>
        <Rate onChange={this.handleChange} value={value} />
        {value && <span className="ant-rate-text">{value} stars</span>}
      </span>
    );
  }
}

ReactDOM.render(<Rater />, mountNode);

  • A
    A
  • A
    A
  • A
    A
  • A
    A
  • A
    A

Replace the default star to other character like alphabet, digit, iconfont or even Chinese word.

import { Rate, Icon } from 'antd';

ReactDOM.render(
  <div>
    <Rate character={<Icon type="heart" />} allowHalf />
    <br />
    <Rate character="A" allowHalf style={{ fontSize: 36 }} />
    <br />
    <Rate character="" allowHalf />
  </div>
, mountNode);

Support select half star.

import { Rate } from 'antd';

ReactDOM.render(<Rate allowHalf defaultValue={2.5} />, mountNode);

Read only, can't use mouse to interact.

import { Rate } from 'antd';

ReactDOM.render(<Rate disabled defaultValue={2} />, mountNode);

API#

PropertyDescriptiontypeDefault
countstar countnumber5
valuecurrent valuenumber-
defaultValuedefault valuenumber0
onChangecallback when select valueFunction(value: number)-
onHoverChangecallback when hover itemFunction(value: number)-
allowHalfwhether to allow semi selectionbooleanfalse
disabledread only, unable to interactbooleanfalse
charactercustom character of rateReactNode<Icon type="star" />
classNamecustom class name of ratestring-
stylecustom style object of rateobject-