hasura / gatsby-gitbook-starter

Generate GitBook style modern docs/tutorial websites using Gatsby + MDX
https://hasura.io/learn/graphql/react/introduction/
MIT License
984 stars 378 forks source link

emotion-theming doesn't seem to work #44

Closed dstollie closed 4 years ago

dstollie commented 4 years ago

For our style guidelines I wanted to use this starter to have a solid base. Since this repository uses styled components and already implemented emotion-themeing. I though this was the perfect place to store our shared colors and fonts. Unfortunately emotion-theming doesn't seem to work and I don't really understand why it is not.

How to reproduce

  1. Go to src/components/themeProvider.js This is the place where the EmotionThemeProvider is being added. For simplicity reason I added a new ThemeProvider which has it's own theme.
  2. Replace themeProvider.js with the following contents
    
    import * as React from "react";
    import { ThemeProvider as EmotionThemeProvider } from "emotion-theming";
    import defaultTheme from "./theme";
    import styled from "react-emotion";
    import Header from "./Header";
    import "./styles.css";

const Button = styled("div") background: ${props => props.theme.colors.primary}; ;

const theme = { colors: { primary: 'green' } };

export default function ThemeProvider({ children, location }) { return (

{children}

); }


3. Now go back to the site.
4. You should see the text `some text` with a green background. In reality you get an `TypeError: Cannot read property 'primary' of undefined`  error since the `props.theme` property is undefined.

Considering the following documention [emotion-theming](https://emotion.sh/docs/emotion-theming#install). I expect the code above to work.

Can one of you get a working scenario?
praveenweb commented 4 years ago

Probably related to #28 . Let me try this out with the current version and see if it works. Else need to update dependencies to latest versions.

alexvuong commented 4 years ago

I am having the same problem as well

praveenweb commented 4 years ago

Hi @dstollie,

This has been fixed via 59eb00f

In your above example, change the import statement

from import styled from 'react-emotion'

to import styled from '@emotion/styled'

and everything should work as expected.

rsexton404 commented 4 years ago

Can be fixed by following the Migrating to Emotion 10 instructions