preactjs / preact-cli

😺 Your next Preact PWA starts in 30 seconds.
MIT License
4.69k stars 375 forks source link

How to set up styled-components #672

Closed aibrahim3546 closed 5 years ago

aibrahim3546 commented 5 years ago

Do you want to request a feature or report a bug?

No

What is the current behaviour?

Intstalled styled-component via npm:

npm install styled-components --save

import styled from 'styled-components';

const Test = styled.div`
  font-size: 40px
`
// .........
render() {
 return (
   <Test>Test</Test>
 );
}

When run npm run start:

Hit this error:

screen shot 2018-11-22 at 12 02 45 pm

Please mention other relevant information.

ForsakenHarmony commented 5 years ago

-was not constructive-

aibrahim3546 commented 5 years ago

The issue was solved:

This is happening because of the version of styled-components which I was using previously is version 4.0.0.

Once I downgrade my styled-components to version ^3.1.6 it was working fine. This is because version 4.0.0 is using the latest reactjs with the support of contextApi, Since preact don't have contextApi this error will occur.

@ForsakenHarmony thank you for suggestion :)

ko06 commented 5 years ago

How can I use styled-component with 4.0.0 with preact?