I read through a simillar topic where the same error was discussed, however that did not solve my problem. I have a simple app component:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
class SearchBox extends Component {
render() {
return (
<form onSubmit = {this.handleClick.bind(this)}>
<input
ref="search"
type="text"
placeholder="username..."/>
<input
type="submit"
value="Search" />
</form>
);
}
handleClick(e) {
e.preventDefault();
let username = this.refs.search.findDOMNode().value;
this.props.fetchUser(username);
this.refs.search.findDOMNode().value = '';
}
fetchUser(username) {
let url = `https://api.github.com/users/${username}`;
this.fetchApi(url);
}
fetchApi(url) {
fetch(url)
.then((res) => res.json())
.then((data) => {
this.setState({
username: data.login,
image: data.avatar_url,
name: data.name,
location: data.location,
followers: data.followers,
following: data.following
})
})
}
}
export default SearchBox;
After rendering the component, I get the following error:
TypeError: this.refs.search.findDOMNode is not a function
20 |
21 | handleClick(e) {
22 | e.preventDefault();
> 23 | let username = this.refs.search.findDOMNode().value;
24 |
25 | this.props.fetchUser(username);
26 | this.refs.search.findDOMNode().value = '';
I tried using the findDOMNode() and also getDOMNode() methods, but without luck. Both of them cause the same error to pop up. Any ideas?