How to fix missing dependency warning when using useEffect React Hook

If you aren’t using fetchBusinesses method anywhere apart from the effect, you could simply move it into the effect and avoid the warning useEffect(() => { const fetchBusinesses = () => { return fetch(“theURL”, {method: “GET”} ) .then(res => normalizeResponseErrors(res)) .then(res => { return res.json(); }) .then(rcvdBusinesses => { // some stuff }) .catch(err => … Read more

What is the difference between using constructor vs getInitialState in React / React Native?

The two approaches are not interchangeable. You should initialize state in the constructor when using ES6 classes, and define the getInitialState method when using React.createClass. See the official React doc on the subject of ES6 classes. class MyComponent extends React.Component { constructor(props) { super(props); this.state = { /* initial state */ }; } } is … Read more

How to get parameter value from query string?

React Router v6, using hooks In react-router-dom v6 there’s a new hook named useSearchParams. So with const [searchParams, setSearchParams] = useSearchParams(); searchParams.get(“__firebase_request_key”) you will get “blablabla”. Note, that searchParams is an instance of URLSearchParams, which also implements an iterator, e.g. for using Object.fromEntries etc. React Router v4/v5, without hooks, generic React Router v4 does not … Read more

Programmatically navigate using React router

React Router v5.1.0 with hooks There is a new useHistory hook in React Router >5.1.0 if you are using React >16.8.0 and functional components. import { useHistory } from “react-router-dom”; function HomeButton() { const history = useHistory(); function handleClick() { history.push(“/home”); } return ( <button type=”button” onClick={handleClick}> Go home </button> ); } React Router v4 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)