相关疑难解决方法(0)

如何将其余的道具传递给反应组件,同时在界面中定义所需的道具

那么这是同样的问题,还是我只是遗漏了什么?

import * as React from 'react';

interface Props {
    value: string;
}

const MyComponent = (props: Props) => {
    const { value, ...rest } = props;

    return (
        <input {...rest} type="text" value={value} />
    );
}

interface ParentState {
    searchText: string;
}

class ParentComponent extends React.Component<{}, ParentState> {
    state: ParentState = {
        searchText: ''
    };

    onSearchTextChanged = (e: React.FormEvent<HTMLInputElement>) => {
        this.setState({
            searchText: e.currentTarget.value
        });
    }

    render() {
        const { searchText } = this.state;

        return (
            <div>
                <h2>Some Text</h2>
                <MyComponent …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs

4
推荐指数
2
解决办法
5510
查看次数

标签 统计

reactjs ×1

typescript ×1