1

While skimming through source code of one of the React UI libraries, I've come across this code pattern (I simplify):

function Test() {
  let Button = "button";
  // ...
  return <Button>Click me</Button>;
}

What's going on here - why does this work?:)

1

1 Answer 1

2

The JSX above is interpreted by React as:

function Test() {
  let Button = "button";
  return React.createElement(
    Button,
    null,
    "Click me"
  );
}

Button is just a string variable, set to "button", that gets passed to React.createElement(...).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.