Does className attribute take on id attribute role in Reactjs?

Since id attributes are rarely used in Reactjs components because id attributes imply that the component will not be reused, are className attributes instead of id? If so, then what is the Reactjs equivalent of the class attribute in HTML?

+4
source share
4 answers

className used for class names for CSS styles, as elsewhere.

You can give something unique classNamefor styling, just as you could give otherwise, idbut it does not mean anything else for another use className, which can never really be a direct equivalent id, because it classNamecan contain several class names, nor one of which should not be unique. (There are also good reasons not to use an identifier for styling , regardless of React).

- id React, , DOM, , , , ref getDOMNode() .

+6

inin-, ids , .

- /. , ( ). mixin, unique-id-mixin.

+1

, React, . , , ( "list" ). ID, . , .

To answer your question, the className attribute is used instead and works just like the class attribute. The reaction / addons module provides a utility for easily creating class values.

0
source

Identifiers for single use (in reagent and in general) or disposable copies.

classNames for multiple use (in React and generally) or for multiple instances - just like classes are used in traditional CSS.

0
source

All Articles