0

for example:

import react from 'react';
import { Link } from 'react-router-dom';

Why are input this {curly brackets}?

DecPK
  • 24,537
  • 6
  • 26
  • 42
  • Curly braces { } are special syntax in JSX. It is used to evaluate a JavaScript expression during compilation, A JS exp can be a variable, function, object, any code. – NsdHSO Jul 13 '22 at 21:48
  • @NsdHSO that's a confusing explanation. It doesn't evaluate an expression at compilation, it destructures a property from an import at runtime in the code here. In JSX, it evaluates the contents as a JS expression at runtime. – ggorlen Jul 13 '22 at 22:05
  • @ggorlen line two ? – NsdHSO Jul 13 '22 at 22:28
  • Yes, line two in OP's code. That's not JSX, it's a destructure of an imported object. You can't destructure a function or "any code". – ggorlen Jul 13 '22 at 22:30
  • if yes, maybe you can read this https://betterprogramming.pub/understanding-the-difference-between-named-and-default-exports-in-react-2d253ca9fc22#:~:text=Exports%20without%20a%20default%20tag,are%20not%20React%2Dcentric%20ideas. I hope this article to help you – NsdHSO Jul 13 '22 at 22:30
  • Why do you think it'll help me? – ggorlen Jul 13 '22 at 22:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/246422/discussion-between-nsdhso-and-ggorlen). – NsdHSO Jul 13 '22 at 22:32
  • Sorry, I don't have time to explain more than I already have. If you read the article you've shared, you'll see no mention of evaluating expressions at compilation, and no mention of JSX, because those things have nothing to do with destructuring imports. – ggorlen Jul 13 '22 at 22:33

0 Answers0