Pixel value in style
When setting size-related styles such as width and height, most of them will be in pixels. At this time
, it will be very troublesome to input px repeatedly . In order to improve efficiency, React will automatically add px to such attributes. such as:
// 渲染成 height: 10px
const style = {
height: 10 };
ReactDOM.render(<Component style={
style}>Hello</Component>, mountNode);
Note that in addition to supporting pixel values in px, some properties also support numbers directly as values. At this time, React does not add
px, such as lineHeight: 10.