React components
organizing files based on content types
Components display portions of apps, such as a header, button, footer and so on. They typically consist of smaller chunks of code in individual files to keep things better organized. Each component tries to do one thing only and that one thing well!
React components come in two basic types:
class-based (an older way)
functional (a newer way)
An example of a simple component in modern React looks something like this:
Then, to use this component, we would import it into another "app" file using an HTML-like JSX tag syntax with <Greeting />
(or, more generally, <ComponentName />
):
If we want to include multiple instances, or multiple components, into our "app" file, we would then need to wrap the return
statement with parentheses and Fragment
s as such:
Last updated