Using ReactDOM.findDOMNode() like this:
const node = ReactDOM.findDOMNode(this);
Will throw a warning in StrictMode:
Warning: findDOMNode is deprecated in StrictMode.
Functional Component (with useRef)
import { useRef, useEffect } from 'react';
function MyComponent() {
const divRef = useRef(null);
useEffect(() => {
if (divRef.current) {
divRef.current.focus(); // example usage
}
}, []);
return Hello;
}
Class Component (with createRef)
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.myRef = React.createRef();
}
componentDidMount() {
if (this.myRef.current) {
this.myRef.current.focus(); // or do something else
}
}
render() {
return Hello;
}
}
If you’re using a library (e.g., Material-UI, React Transition Group) that internally uses findDOMNode, you can usually:
You are updating title directly on the component’s state, but the state only contains editTodo, not a top-level title field. That’s why your function seems “not working” — you’re updating the wrong part of the state.
Since editTodo is part of the state, and title is a nested property inside it, you need to update it like this:
handleChange = (event) => {
this.setState(prevState => ({
editTodo: {
...prevState.editTodo,
title: event.target.value
}
}));
}
This properly updates editTodo.title in the state, and now value={this.state.editTodo.title} will reflect what you type.
Right now, editTodo.title is initially “”. So the edit field is empty when you open the modal. You may want to set it from props when handleShow is called:
handleShow = () => {
const { id, title, isCompleted } = this.props.todo;
this.setState({
show: true,
editTodo: { id, title, isCompleted }
});
}
This error could occur if you’re accidentally using a function where JSX is expected, for example:
<p>{this.props.handleDelete(id)}</p>> // ❌ BAD
This returns void and is invalid.
Instead:
<p onClick={() => this.props.handleDelete(id)}>Delete</p> // âś… GOOD
Work with our skilled Node developers to accelerate your project and boost its performance.
Hire Node.js Developers