Mình đang tìm hiểu React, mắc ở chỗ lấy dữ liệu của 1 component từ bên ngoài hoặc component khác.
Ví dụ:
(Copy từ Vim nên nó bị mấy dấu | các bạn đừng để ý nhé)
ComplieButton.jsx
class ComplieButton extends React.Component
{
render()
{
¦ return (
¦ ¦ <button
¦ ¦ ¦ className="myButton"
¦ ¦ >
¦ ¦ ¦ Complie
¦ ¦ </button>
¦ );
}
}
Editor.jsx
class Editor extends React.Component
{
constructor(props)
{
¦ super(props);
¦ this.state = {
¦ ¦ value: props.value,
¦ };
}
render()
{
¦ return (
¦ ¦ <AceEditor
¦ ¦ ¦ onChange={this.onChange.bind(this)}
¦ ¦ ¦ value={this.state.value}
¦ ¦ />
¦ );
}
}
Mình muốn là làm sao để lấy được giá trị của Editor.state.value từ component ButtonComplie
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?