-
更新create-react-app的新版本,找到项目中的package.json,
"react-scripts": "4.0.3",将版本号改成最新版,之后运行npm install -
JSX: part of React allows you to write some HTML syntax in javaScript.当我们写HTML时候实际上是在写JSX,这些JSX需要import到React中才能工作。这就是为什么要有
import React from 'react' -
react img 标签必须闭合,否则报错;
-
return 只能返回一个数值;除非使用Fragment
-
关于{}
The curly braces are a special syntax to let the JSX parser know that it needs to interpret the contents in between them as JavaScript instead of a string. This process is generally referred to as "interpolation".
You need {} when you want to use a JavaScript expression like a variable or a reference inside JSX.
-
Fragment blog.logrocket.com/rendering-c…
解决了只能return一个的问题。
import React, {Fragment} from "react";
function FAQ() {
return (
<Fragment>
<p>Q. What is React?</p>
<p>A. A JavaScript library for building user interfaces</p>
<p>Q. How do I render sibling elements?</p>
<p>A. Use Fragments</p>
</Fragment>
);
}