JSX and Adding style in React JS

Writing markup with JSX

The markup syntax you’ve seen above is called JSX. It is optional, but most React projects use JSX for its convenience. All of the tools we recommend for local development support JSX out of the box. JSX is stricter than HTML. You have to close tags like <br/>. Your component also can’t return multiple JSX tags. You have to wrap them into a shared parent, like a <div>...</div> or an empty <>... </> wrapper: function AboutPage() { return (

<>

        <h1>About</h1>

        <p>Hello there.<br/>How do you do?</p>

    </>

); } If you have a lot of HTML to port to JSX, you can use an online converter.

Adding styles

In React, you specify a CSS class with className. It works the same way as the HTML class attribute:

<img className="avatar" />

Then you write the CSS rules for it in a separate CSS file: /* In your CSS */ .avatar {

border-radius: 50%;

} React does not prescribe how you add CSS files. In the simplest case, you’ll add a <link> tag to your HTML. If you use a build tool or a framework, consult its documentation to learn how to add a CSS file to your project.

Comments

Popular posts from this blog

Angular JS Course Roadmap

How can we motivated while coding?

What is rapid Api?