我正在嘗試解決React有狀態組件和無狀態組件之間的區別。React組件從有狀態到無狀態(差異)
糾正我,如果我錯了:
所以,這是一個有狀態的組件:
import React from "react";
export class Mycomponent extends React.Component {
render() {
return (
<div>
<p>My Component</p>
</div>
);
}
}
和無狀態組件是如何將上面的有什麼不同?
你有什麼考慮得出結論,這是一個有狀態組件?正如我現在看到的那樣,它不是有狀態的,也不是無狀態的。它只是靜態的。 – Leandro
據我所知,無狀態組件僅從道具中獲取所有渲染數據。一旦你開始擺弄'this.state',你就得到了一個有狀態的組件。 – Leandro
可能的重複:https://stackoverflow.com/questions/34512696/reactjs-difference-between-stateful-and-stateless –