# How to get an input value using “refs” in react-bootstrap form?

**URL:** <https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [December 11, 2016, 11:40am UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227 "2016-12-11T11:40:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Y-Taras](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/y-taras/32/161265_2.png) [@Y-Taras](https://forum.freecodecamp.org/u/Y-Taras)\
**Post date:** [December 11, 2016, 11:40am UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227/1 "2016-12-11T11:40:29Z")

</div>

I’m trying to create a form that appears in modal. So when user input a value, that value is stored in local storage. Here’s a picture that help’s you to understand what I mean:  
[![](https://i.sstatic.net/XK0jv.png) ](https://i.sstatic.net/XK0jv.png)  
Here is the code of the form:

```
function FieldGroup({id, label, help, ...props}) {
    return (
        <ReactBootstrap.FormGroup controlId={id}>
            <ReactBootstrap.ControlLabel>{label}</ReactBootstrap.ControlLabel>
            <ReactBootstrap.FormControl {...props} />
            {help && <ReactBootstrap.HelpBlock>{help}</ReactBootstrap.HelpBlock>}
        </ReactBootstrap.FormGroup>
    );
}

const formInstance = (
    <form>
        <FieldGroup
            id="formControlsText"
            type="text"
            label="Text"
            placeholder="Recipe Name"
            inputRef={ref => { this.input = ref; }}
        />
        <ReactBootstrap.FormGroup controlId="formControlsTextarea">
            <ReactBootstrap.ControlLabel>Ingredients</ReactBootstrap.ControlLabel>
            <ReactBootstrap.FormControl componentClass="textarea" placeholder="Enter Ingredients" />
        </ReactBootstrap.FormGroup>
    </form>
);  

```

As I’ve read in bootstrap React tutorial, I should add  
`<FormControl inputRef={ref => { this.input = ref; }} />` to the FormControl props. But after adding it I get an error when modal form is invoked:  
 ![](https://global.discourse-cdn.com/freecodecamp/optimized/3X/1/d/1d9ba9f04bd781ce9790da47de6bef5448e7954b_2_690x40.png)

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [December 11, 2016, 6:22pm UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227/2 "2016-12-11T18:22:25Z")

</div>

Can’t use `ref` there.

> You may not use the ref attribute on functional components because they don’t have instances. You can, however, use the ref attribute inside the render function of a functional component:

> **[Refs and the DOM – React](https://legacy.reactjs.org/docs/refs-and-the-dom.html)**
>
> A JavaScript library for building user interfaces

---

<div class="post-metadata">

**Author:** ![Y-Taras](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/y-taras/32/161265_2.png) [@Y-Taras](https://forum.freecodecamp.org/u/Y-Taras)\
**Post date:** [December 11, 2016, 9:09pm UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227/3 "2016-12-11T21:09:44Z")

</div>

thanks anyway, though I’ve already found this answer 🙂

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [December 11, 2016, 9:19pm UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227/4 "2016-12-11T21:19:22Z")

</div>

Could you post your solution here in case someone else needs it?

---

<div class="post-metadata">

**Author:** ![mangaonkarkiran](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@mangaonkarkiran](https://forum.freecodecamp.org/u/mangaonkarkiran)\
**Post date:** [September 28, 2017, 7:21am UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227/6 "2017-09-28T07:21:37Z")

</div>

How to get an input value using “refs” in react-bootstrap form? i didn’t get answer

---

<div class="post-metadata">

**Author:** ![Y-Taras](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/y-taras/32/161265_2.png) [@Y-Taras](https://forum.freecodecamp.org/u/Y-Taras)\
**Post date:** [September 28, 2017, 7:41am UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227/7 "2017-09-28T07:41:56Z")

</div>

Maybe answers in next link would help you

> <https://stackoverflow.com/questions/41085220/how-to-get-an-input-value-using-refs-in-react-bootstrap-form>

---

<div class="post-metadata">

**Author:** ![mangaonkarkiran](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@mangaonkarkiran](https://forum.freecodecamp.org/u/mangaonkarkiran)\
**Post date:** [September 28, 2017, 8:10am UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227/8 "2017-09-28T08:10:20Z")

</div>

thanks dear i got the answers with above link  
\<FieldGroup  
componentClass="input"  
type="text"  
label="First Name"  
placeholder="Enter recipe title"  
inputRef={(ref) =\> {this.firstName = ref}}  
/\>  
console.log(this.firstName.value);

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 18, 2021, 8:23am UTC](https://forum.freecodecamp.org/t/how-to-get-an-input-value-using-refs-in-react-bootstrap-form/64227/9 "2021-01-18T08:23:57Z")

</div>

Closed on January 18, 2021, 8:23am UTC


