繁体   English   中英

在 typescript 中错误地导入和使用类型的属性

[英]importing and using properties of types incorrectly in typescript react

我无法在组件之间获取某种类型的道具。 我有一个 class 组件,它已经通过了类型道具。 但我需要传递另一种类型来引用获取方法的 id 道具。 我不确定我是否解释正确,所以这里是代码。

interface ChannelEntryType {
    entry: string
    id: string
}

interface AuthProps {
    sessionToken: string | undefined | null
}

interface ChannelEntryState {
    channelEntry: ChannelEntryType[]
    updateActive: boolean
    createActive: boolean
    updatedChannelEntry: ChannelEntryType
}

export default class ChannelEntry extends Component<AuthProps, ChannelEntryState> {
    constructor(props: AuthProps) {
        super(props)
        this.state = {
            channelEntry: [],
            updateActive: false,
            createActive: false,
            updatedChannelEntry: {
                entry: "",
                id: ""
            }
        }
    }

getChannelEntry = (id: string) => {
    console.log("get channel entry called")
    console.log()
    fetch(`${APIURL}/channelentry/${id}`, {
        method: "GET",
        headers: new Headers({
            "Content-Type": "application/json",
            "Authorization": `${this.props.sessionToken}`
        })
    })
    .then(response => response.json())
    .then(data => {
        console.log(data)
        this.setState({
            channelEntry: data
        })
        console.log(this.state.channelEntry, "channel entry called")
    })
    .catch(err => console.log(err))
}

我正在尝试导入另一个 id 道具以传递给 getChannelEntry 但不知道如何将另一个道具类型传递给 class 组件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM