Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple components break react #2

Open
o-t-w opened this issue Mar 22, 2019 · 0 comments
Open

multiple components break react #2

o-t-w opened this issue Mar 22, 2019 · 0 comments

Comments

@o-t-w
Copy link

o-t-w commented Mar 22, 2019

Not entirely sure this is the fault of this dependency, but...
I used this to make a card component responsive. When I import it once, everything is OK. When I import it more than once, I get the error message ReferenceError: React is not defined

    <div className="App">
      <Card />
      <Card />
    </div>

This is my Card component:

/** @jsx jsx */

import React, { useRef, useState } from "react";
import { css, jsx } from "@emotion/core";

import useResizeObserver from "react-resize-observer-hook";

function Card(props) {
  const [dimensions, setDimensions] = useState({ width: 100, height: 50 });
  const parentRef = useRef(null);

  useResizeObserver(parentRef, entry =>
    setDimensions({
      width: entry.width,
      height: entry.height
    })
  );

  const style = css({
    display: "flex",
    flexDirection: dimensions.width > 600 ? "row" : "column",
    "& div": {
      marginTop: 10,
      flex: 1
    },
    "& img": {
      objectFit: "cover",
      flex: 1
    },
    "& h2": {
      paddingLeft: 10,
      paddingRight: 10
    },
    "& p": {
      paddingLeft: 10,
      paddingRight: 10
    }
  });

  return (
    <div css={style} ref={parentRef}>
      <img
        src="ribena.webp"
        alt=""
      />
      <div>
        <h2>placeholder</h2>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Quidem
          molestiae, vitae esse et dignissimos consequuntur provident eligendi
          labore beatae laboriosam.
        </p>
      </div>
    </div>
  );
}

export default Card;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant