P
P
PlasterTom2018-02-06 19:14:06
React
PlasterTom, 2018-02-06 19:14:06

Are props needed?

Example from documentation:

function Welcome(props) {
      return <h1>Hello, {props.name}</h1>;
    }

Can I write code of this type, without any props, if my component actually appears only once on the site? And what is the right way to do it? (Specifically, there is a portfolio site with an "about me" page that contains information about education, experience, etc.) Probably, for a site like this, react is not the best choice at all, but I chose it so simply in order to enter to the library.
function Welcome() {
      return <h1>Hello, World!</h1>;
    }

P.S. How to do export default for functional components?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-02-06
@PlasterTom

If you're not using props , don't post.
When used, you can do destructuring:

function Welcome({ name }) {
  return <h1>Hello, {name}</h1>;
}

Second question:
export default function Welcome() {
  return <h1>Hello, World!</h1>;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question