Rate

Rate component.

When To Use#

  • Show evaluation.

  • A quick rating operation on something.

Examples

The simplest usage.

expand codeexpand code
import { Rate } from 'antd';

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

Add copywriting in rate components.

expand codeexpand code
import { Rate } from 'antd';

class Rater extends React.Component {
  state = {
    value: 3,
  }
  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.

expand codeexpand code
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.

expand codeexpand code
import { Rate } from 'antd';

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

Read only, can't use mouse to interact.

expand codeexpand code
import { Rate } from 'antd';

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

API#

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