The code below throws a typeerror: 'Cannot read property "focus" of null'. Going off of react's documentation this should work. NOTE: The parent component implements redux connect method, but I'm not sure why this would have any effect on this component.
import React, { Component, createRef } from 'react';
import './Card.scss';
const Card = ({isEditing, item, onBlur, onChange}) => {
let inputText = createRef();
const editing = (editMode) => {
if (editMode) {
inputText.current.focus();
}
return e => {
e.stopPropagation();
isEditing(item, editMode);
};
}
const update = () => {
return e => {
onChange(item.id, e.target.value);
}
}
return (
<div className="card">
<img className="card-image" src="https://picsum.photos/200/200"
alt="no image display" />
<div className="card-body">
{item.edited ? (
<div>
<input type="text" ref={inputText} onClick={e =>
e.stopPropagation()} value={item.name} onBlur=
{editing(false)}
onChange=
{update()} />
</div>
) : (
<h3 className="card-title" onClick={editing(true)} >
{item.name}
</h3>
)}
</div>
</div>
);
}
export default Card;