Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React ref using reactstrap Input Module doesn't have Value prop

I have a react component with the following input element:

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" />
    )
}

I want to grab the value Prop from the ref {this.test} however, when I console log I receive the following output.

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

How do i get a value prop using reactstrap "Input" tag instead of the built in HTML "input" Dom element.

like image 769
muso mwale Avatar asked Dec 14 '22 12:12

muso mwale


1 Answers

Use innerRef instead of ref with your Input component.

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

like image 51
Craig Gehring Avatar answered Dec 21 '22 11:12

Craig Gehring