I try use last version of antd(3.10.0) and react(16.5.2).
I use the new way of ref according to .html
this.myRef = React.createRef();
when it rend,should like:
rend(){
<Select style={{ width: 200 }} ref={this.myRef}>
{Object.entries(this.state.catedict)
.map(en => <Option key={en[0]}>{en[1]}</Option>)}
</Select>
}
But when I want to get the value of Input or Select
I try to:
console.log(this.myRef.current.value);
But only get wrong result.
I find even:
console.log(this.myRef.current);
the result is:
t {props: {…}, context: {…}, refs: {…}, updater: {…}, saveSelect: ƒ, …}
context: {}
props: {style: {…}, children: Array(2), prefixCls: "ant-select", showSearch: false, transitionName: "slide-up", …}
rcSelect: t {props: {…}, context: {…}, refs: {…}, updater: {…}, onInputChange: ƒ, …}
refs: {}
renderSelect: ƒ (n)
saveSelect: ƒ (n)
state: null
updater: {isMounted: ƒ, enqueueSetState: ƒ, enqueueReplaceState: ƒ, enqueueForceUpdate: ƒ}
_reactInternalFiber: Na {tag: 2, key: null, type: ƒ, stateNode: t, return: Na, …}
__proto__: v
I want give the value of Select. How should I do?
I try use last version of antd(3.10.0) and react(16.5.2).
I use the new way of ref according to https://reactjs/docs/refs-and-the-dom.html
this.myRef = React.createRef();
when it rend,should like:
rend(){
<Select style={{ width: 200 }} ref={this.myRef}>
{Object.entries(this.state.catedict)
.map(en => <Option key={en[0]}>{en[1]}</Option>)}
</Select>
}
But when I want to get the value of Input or Select
I try to:
console.log(this.myRef.current.value);
But only get wrong result.
I find even:
console.log(this.myRef.current);
the result is:
t {props: {…}, context: {…}, refs: {…}, updater: {…}, saveSelect: ƒ, …}
context: {}
props: {style: {…}, children: Array(2), prefixCls: "ant-select", showSearch: false, transitionName: "slide-up", …}
rcSelect: t {props: {…}, context: {…}, refs: {…}, updater: {…}, onInputChange: ƒ, …}
refs: {}
renderSelect: ƒ (n)
saveSelect: ƒ (n)
state: null
updater: {isMounted: ƒ, enqueueSetState: ƒ, enqueueReplaceState: ƒ, enqueueForceUpdate: ƒ}
_reactInternalFiber: Na {tag: 2, key: null, type: ƒ, stateNode: t, return: Na, …}
__proto__: v
I want give the value of Select. How should I do?
Share Improve this question asked Oct 9, 2018 at 17:17 user504909user504909 9,55916 gold badges74 silver badges113 bronze badges2 Answers
Reset to default 5You can get it by the ref,the antd select is hoc of rc-select,if you want to get the value,you still get it by ref.rcSelect
`the react dom`
<Select ref={r => this.ctryListRef = r} />
`the js code`
console.log(this.ctryListRef.rcSelect.state.value)
by the rcSelect.state.value, you can get the value.
In addition, you can get antd textArea value, it's just another hoc~
save value of Select
on every change! and use it when you want.
<Select style={{ width: 200 }} onChange={(value)=>{
this.selectValue = value;
}}>
and use it in other place:
console.log('Select Value', this.selectValue)