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

add raw HTML with inside Gatsby React page

You can inject external scripts (with no npm modules) to gatsby.js project in many ways. Prefer to use respective gatsby-plugin for “web-analytics” scripts. Using require() : Create a file in your project myScript.js and paste the script content Add const myExtScript = require(‘../pathToMyScript/myScript’) to a statefull component at the Pages folder inside render() and before … Read more

How do I get the current url in Gatsby?

You can get the current url using the location prop from the @reach/router Location component. import PropTypes from ‘prop-types’; import React, { Component } from ‘react’; import { Location } from ‘@reach/router’; class SomeComponent extends Component { static propTypes = { location: PropTypes.object.isRequired } render() { const { location } = this.props; return <div>{JSON.stringify(location)}</div>; } … Read more

Reusable Gatsby-Image Component with dynamic image sources

This may answer your question: The final code: import React from ‘react’; import { StaticQuery, graphql } from ‘gatsby’; import Img from ‘gatsby-image’; // Note: You can change “images” to whatever you’d like. const Image = props => ( <StaticQuery query={graphql` query { images: allFile { edges { node { relativePath name childImageSharp { fluid(maxWidth: … Read more

GatsbyJs client only paths goes to 404 page when the url is directly accessed in browser in “production”

The Why While the client-side router knows about this path, there is no corresponding HTML file. When the browser looks at the site it first loads the 404.html file generated by gatsby, which includes the client-side router. Once the router completes its initialization it reads the path and loads the correct page. Meaning you end … Read more

How do I add google fonts to a gatsby site

You can also use react-helmet, which is discussed in the gatsby tutorial. Include a google fonts link element within the helmet component. Like this: <Helmet> <link href=”https://fonts.googleapis.com/css?family=Open+Sans” rel=”stylesheet”/> </Helmet> I ended up going down this route because I had already done some styling manually, and when I tried using Typography it made a bunch of … Read more

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