我开始学习 React js,并谈到了解构 props 的话题。通常我们做的是我们解构 props 然后使用属性就像下面的 Greet 组件中的代码
import React from "react";
const Greet = props => {
const { name, heroName } = props; //here I destructured it
return (
<div>
<h1>
Hello {name} a.k.a {heroName}
</h1>{" "}
// and then use simply name and heroName
</div>
);
};
export default Greet;
Run Code Online (Sandbox Code Playgroud)
这是我的 App 组件
import React from "react";
import logo from "./logo.svg";
import "./App.css";
import Greet from "./components/Greet";
function App() {
return (
<div className="App">
<Greet name="kaptan" …Run Code Online (Sandbox Code Playgroud)