使用reactstrap输入模块的React ref没有Value prop

问题描述 投票:0回答:1

我有一个带有以下输入元素的react组件:

import React, {
    Component
} from 'react';
import {Input } from 'reactstrap';     
constructor(props) {
    super(props)   
    this.test = React.createRef();       
}

render() {
    console.log(this.test.current)
    return (
         <Input ref={this.test} defaultValue = "This is the default" />
    )
}

我想从ref {this.test}中获取值Prop但是,当我在控制台日志中收到以下输出时。

Input {props: {…}, context: {…}, refs: {…}, updater: {…}, getRef: ƒ, …}
context: {}
focus: ƒ ()
getRef: ƒ ()
props: {defaultValue: "This is the default", onChange: ƒ, type: "text"}
refs: {}
state: null
updater: {isMounted: ƒ, enqueueSetState: ƒ, enqueueReplaceState: ƒ, enqueueForceUpdate: ƒ}
_reactInternalFiber: FiberNode {tag: 1, key: null, elementType: ƒ, type: ƒ, stateNode: Input, …}
_reactInternalInstance: {_processChildContext: ƒ}
isMounted: (...)
replaceState: (...)
__proto__: Component

如何使用reactstrap“Input”标签而不是内置的HTML“input”Dom元素获得值prop。

javascript reactjs reactstrap
1个回答
0
投票

使用输入组件使用innerRef而不是ref。

https://reactstrap.github.io/components/form/

© www.soinside.com 2019 - 2024. All rights reserved.