React: useState or useRef?

The main difference between both is : useState causes re-render, useRef does not. The common between them is, both useState and useRef can remember their data after re-renders. So if your variable is something that decides a view layer render, go with useState. Else use useRef I would suggest reading this article.

How can I reset a react component including all transitively reachable state?

To ensure that the implicit browser state you mention and state of children is reset, you can add a key attribute to the root-level component returned by render; when it changes, that component will be thrown away and created from scratch. render: function() { // … return <div key={uniqueId}> {children} </div>; } There’s no shortcut … Read more

How to include a Font Awesome icon in React’s render()

If you are new to React JS and using create-react-app cli command to create the application, then run the following NPM command to include the latest version of font-awesome. npm install –save font-awesome import font-awesome to your index.js file. Just add below line to your index.js file import ‘../node_modules/font-awesome/css/font-awesome.min.css’; or import ‘font-awesome/css/font-awesome.min.css’; Don’t forget to … Read more

Typescript + React/Redux: Property “XXX” does not exist on type ‘IntrinsicAttributes & IntrinsicClassAttributes

So after reading through some related answers (specifically this one and this one and looking at @basarat’s answer to the question, I managed to find something that works for me. It looks (to my relatively new React eyes) like Connect was not supplying an explicit interface to the container component, so it was confused by … Read more

React Router Pass Param to Component

I used this to access the ID in my component: <Route path=”/details/:id” component={DetailsPage}/> And in the detail component: export default class DetailsPage extends Component { render() { return( <div> <h2>{this.props.match.params.id}</h2> </div> ) } } This will render any ID inside an h2, hope that helps someone.

JSX or HTML autocompletion in Visual Studio Code

2022: Straightforward way to add JSX/HTML autocomplete for .js files in React projects… First, open VSCode’s settings.json. To open settings.json, press Ctrl + , (or Cmd+, on Mac), then click the Open JSON button shown below. Optionally, if you don’t want to set this globally, you can create a .vscode/settings.json file at the project root. … Read more

Passing object as props to jsx

Is this possible? Yes its possible, but the way you are sending it is not correct. The meaning of <MyJsx commonProps /> is: <MyJsx commonProps={true} /> So if you don’t specify any value, by default it will take true. To pass the object, you need to write it like this: const commonProps = {myProp1: ‘prop1’,myProp2: … Read more

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