Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S1 L16 - Handling User Event #5

Open
ngminhtrung opened this issue Mar 22, 2018 · 0 comments
Open

S1 L16 - Handling User Event #5

ngminhtrung opened this issue Mar 22, 2018 · 0 comments

Comments

@ngminhtrung
Copy link
Contributor

import React, { Component } from 'react';

class SearchBar extends Component {
    render() {
        return <input onChange={this.onInputChange} />;
    }

    onInputChange(event) {
        console.log(event.target.value);
    }
}

export default SearchBar;

Cần nhớ: Hóa ra bản thân mỗi sự kiện đã là 1 object, được truyền thông qua onChange vào hàm xử lý event là onInputChange(). Muốn biết object event trông như thế nào, thì có thể console.log luôn event thay vì event.target.value. Ví dụ đây là kết quả của console.log(event).

Lưu ý: Có thể gọi là eventObject hay bất kỳ tên gì chứ không cần bắt buộc chỉ là event, tất tật đều trỏ đến object chứa thông tin về sự kiện hết.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant