Câu hỏi phỏng vấn Reactjs
Câu hỏi

How would you write an inline style in React?

Câu trả lời

To write an inline style in React, you would create a JavaScript object containing CSS properties and their corresponding values, and then assign this object to the style attribute of a JSX element. In React, the CSS properties within the style object must be written in camelCase syntax, as opposed to the kebab-case used in traditional CSS.

Here's an example of how you might write an inline style in React:

const divStyle = {
  color: 'blue',
  backgroundColor: 'lightgray',
  padding: '10px',
  borderRadius: '5px'
};

function MyStyledComponent() {
  return <div style={divStyle}>Stylish Div</div>;
}

In this example, divStyle is a JavaScript object where each key-value pair represents a CSS property and its value. The style attribute of the div JSX element is then set to divStyle, applying the styles directly to that element[2][4][6].

It's important to note that while inline styles are convenient...

entry

entry

Gợi ý câu hỏi phỏng vấn

middle

What are Pure Components?

middle

Why do class methods need to be bound to a class instance?

junior

What happens when you call setState ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào