Skip to content

S1 L16 - Handling User Event #5

@ngminhtrung

Description

@ngminhtrung
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions