React Helmet: Facebook Open Graph

Most search engines and crawlers use server’s response directly, not allowing you to alter it with javascript. So yes, what you need is server-side rendering. Or, you can use tools like gatsbyjs, react-static. Basically, they render your components into HTML files beforehand.

In React Router v6, how to check form is dirty before leaving page/route

Update: Prompt, usePrompt and useBlocker have been removed from react-router-dom. This answer will not currently work, though this might change. The github issue, opened Oct 2021, is here The answer… This answer uses router v6. You can use usePrompt. usePrompt will show the confirm modal/popup when you go to another route i.e. on mount. A … Read more

Dynamic loading of react components

Basically it boils down to pre-creating all the chunks you will ever need. Then you just need a way to dynamically refer to them. Here’s the solution I based mine on: http://henleyedition.com/implicit-code-splitting-with-react-router-and-webpack and here’s what I do since I don’t use React Router (side note: i dont find it to be a good match for … Read more

Component not re rendering when value from useContext is updated

The issue is likely that you’re mutating the array (rather than setting a new array) so React sees the array as the same using shallow equality. Changing your addOrder method to assign a new array should fix this issue: const addToOrder = (idToAdd, quantityToAdd = 1) => setProducts([ …products, { id: idToAdd, quantity: quantityToAdd } … Read more

Equivalent in React of *ngFor in Angular 2

You can use map on numbers and create the options dynamically like this: <select> { numbers.map(el => <option value={el} key={el}> {el} </option>) } </select> Check this example: var numbers = […Array(100).keys()]; var App = () => { return( <select> { numbers.map(el => <option value={el} key={el}> {el} </option>) } </select> ) } ReactDOM.render(<App/>, document.getElementById(‘app’)) <script src=”https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js”></script> … Read more

Generate single physical javascript file using create-react-app

An alternative solution, as suggested here, is to use the rewire package to manipulate Create React App’s webpack config, e.g. Create a new file scripts/build.js // npm install rewire const rewire = require(‘rewire’); const MiniCssExtractPlugin = require(‘mini-css-extract-plugin’); const defaults = rewire(‘react-scripts/scripts/build.js’); const config = defaults.__get__(‘config’); // Consolidate chunk files instead config.optimization.splitChunks = { cacheGroups: { … Read more

DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated

Update 2021, Feb 25 Html-webpack-plugin v5 is released, just run npm i -D html-webpack-plugin@latest or npm uninstall html-webpack-plugin npm i -D html-webpack-plugin Original answer This is mostly related to html-webpack-plugin, and while its new version 5 (integrated with webpack v5) is still in beta, you should update it manually: npm show html-webpack-plugin version 4.5.1 npm … Read more