ReactJs Refs not working reactjs refs example,reactjs refs deprecated,reactjs refs,reactjs refs

I am trying to do something similar to this. However, I would like for the input field to stay in focus until the user clicks anywhere but within the menu or any of the submenus. I am trying to use refs following the React documentation (trying to duplicate it in fact) but I cannot get it to work.

Error

"Uncaught TypeError: _this.textInput.current.focus is not a function"

Code (input field component)

import React from 'react';
import styled from 'styled-components';

export default class TextInput extends React.Component {
    constructor(props) {
        super(props);
        this.textInput = React.createRef();
    }

    focusTextInput = () => {
        this.textInput.current.focus();
    }

    render = () => {
        return (
            <div>
                <TextInputField
                    font={this.props.font}
                    fontSize={this.props.fontSize}
                    placeholder={"What?"}
                    type="text"
                    value={this.props.title}
                    titleLength={this.props.titleLength}
                    onChange={this.props.change}
                    onFocus={this.props.focus}
                    onBlur={this.props.blur}
                    id="titleInput"
                    textColor={this.props.textColor}
                    ref={this.textInput} />
                <input
                    type="button"
                    value="Focus the text input"
                    onClick={this.focusTextInput}
                />
            </div>
        );
    }
}

const TextInputField = styled.input`
width: 90%;
height: ${props => props.fontSize * 1.25}vw;
line-height: ${props => props.fontSize * 1.25}vw;
text-align: center;
position: absolute;
bottom: -12.5vw;
left: 5%;
margin: 0 auto;
background-color: transparent;
border: transparent;
text-overflow: ellipsis;
color: ${props => props.textColor};
font-size: ${props => props.fontSize}vw;
font-family: ${props => props.font};
&:hover {
  background-color: rgba(0, 0, 0, 0.2);
}
&:focus {
  outline: none;
  background-color: rgba(0, 0, 0, 0.5);
}
`;
Answer:1



  1. reactjs refs example
  2. reactjs refs deprecated
  3. reactjs refs
  4. reactjs refs array
  5. reactjs refs value
  6. reactjs refs undefined
  7. reactjs refs and the dom
  8. react useref in loop

I have an array of objects. I want my function clicked() to add a new parameter to my object (visible: false). I'm not sure how to tell react to update my state for a specific key without re-creating ...

I have an array of objects. I want my function clicked() to add a new parameter to my object (visible: false). I'm not sure how to tell react to update my state for a specific key without re-creating ...

I have an app where I have a horizontal list of items, that when you click them they should disappear and trigger some action. Minimal demonstration here: Code: https://codesandbox.io/s/5xpkn3nzxl ...

I have an app where I have a horizontal list of items, that when you click them they should disappear and trigger some action. Minimal demonstration here: Code: https://codesandbox.io/s/5xpkn3nzxl ...