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

Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object

In my case (using Webpack) it was the difference between: import {MyComponent} from ‘../components/xyz.js’; vs import MyComponent from ‘../components/xyz.js’; The second one works while the first is causing the error. Or the opposite.

A component is changing an uncontrolled input of type text to be controlled error in ReactJS

The reason is, in state you defined: this.state = { fields: {} } fields as a blank object, so during the first rendering this.state.fields.name will be undefined, and the input field will get its value as: value={undefined} Because of that, the input field will become uncontrolled. Once you enter any value in input, fields in … Read more

Show or hide element in React

React circa 2020 In the onClick callback, call the state hook’s setter function to update the state and re-render: const Search = () => { const [showResults, setShowResults] = React.useState(false) const onClick = () => setShowResults(true) return ( <div> <input type=”submit” value=”Search” onClick={onClick} /> { showResults ? <Results /> : null } </div> ) } … Read more

Detect click outside React component

The following solution uses ES6 and follows best practices for binding as well as setting the ref through a method. To see it in action: Hooks Implementation Class Implementation After React 16.3 Class Implementation Before React 16.3 Hooks Implementation: import React, { useRef, useEffect } from “react”; /** * Hook that alerts clicks outside of … Read more

Call child method from parent

First off, let me express that this is generally not the way to go about things in React land. Usually what you want to do is pass down functionality to children in props, and pass up notifications from children in events (or better yet: dispatch). But if you must expose an imperative method on a … Read more

Why do we need middleware for async flow in Redux?

What is wrong with this approach? Why would I want to use Redux Thunk or Redux Promise, as the documentation suggests? There is nothing wrong with this approach. It’s just inconvenient in a large application because you’ll have different components performing the same actions, you might want to debounce some actions, or keep some local … Read more

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