score:30
assuming you have successfully installed node-sass
in a typescript create-react-app
react application, just as you would add/import a css stylesheet by doing the following:
import './mystyles.css';
for a scss stylesheet, you would simply change the file type:
import './mystyles.scss';
in your example you simple need to treat it as a import a module for its side effects only instead of a default import like you are currently attempting.
you can also treat it as a scss module by updating the scss filename to mystyles.module.scss
and importing it as follows:
import styles as './mystyles.module.scss';
i was able to achieve both bits of functionality doing the following as sass/scss support is built in by default in react-scripts@2.0.0
and higher projects:
- created a typescript create-react-app using command
npx create-react-app my-app --template typescript
- navigated into the create
directory and install node-sass using command
npm install --save node-sass
- changed default generated
app.css
toapp.scss
- changed import in
app.tsx
fromimport './app.css';
toimport './app.scss';
make sure you have node-sass
installed. if that doesn't help, you may need to revisit how you created/converted your create-react-app
to be in typescript.
you need to either import it as import './mystyles.scss';
or actually put module
in the file name and import it as import whatever from './mystyles.module.scss';
.
Source: stackoverflow.com
Related Query
- How to use React with Typescript and SASS
- How to use emotion/styled with React and Typescript
- How to use mixins with Typescript and React JSX (TSX)
- How to use Typescript with React Router and match
- How to use Facebook Javascript SDK to login and force re-authentication with React Web and Typescript inside of a component
- how to use Sass variables and mixins with react js
- How to use refs in React with Typescript
- How to use TypeScript with withRouter, connect, React.Component and custom properties?
- How to use vw and vh css with React Native
- How to use forwardRef with FunctionComponent in React Native using TypeScript
- How to use Material UI custom theme in React with Typescript
- how to use .env file in a react js with typescript project?
- How to use jest.spyOn with React function component using Typescript
- React Typescript how send props and use it in child component
- How to use Django User Groups and Permissions on a React Frontend with Django Rest Framework
- How do you correctly use React.lazy() in Typescript to import a react component with a generic type parameter?
- How to use HOC with redux compose and Typescript
- How to use Jest with React and Webpack
- How to use srcset 2x with React and Webpack?
- React how to use icon inside Textfield Material-UI with TypeScript
- How to use Refs with Material-ui 4, React 16.8, TypeScript 3.5
- How to use inheritance with React components and es6 classes
- Use onFocus on a div with React and Typescript
- How to test with jest and typescript with types a basic react function component
- How to use Material UI custom variants in React with Typescript
- How to use radium in React typescript (Error: has no properties in common with type 'CSSProperties'. TS2559)?
- How to use React Hook Form with Typescript (Input Component)
- How to use setTimeout() along with React Hooks useEffect and setState?
- How to Use SVG with React and ReasonML?
- How to use Sass and CSS Modules with create-react-app?
More Query from same tag
- query from firebase realtime database
- I got the error unclosed regular expression in my jsfiddle
- JWT LocalStorage vs Cookie
- reactjs charts implementation
- Adding para "id" in react.js url
- How can I hide a link with inline conditional styling in react?
- How do i post a Json data into my state ReactJs
- WordPress InnerBlocks Gutenberg don't save correct
- Fetch data with redux saga
- "ERROR in loader Users/abc/node_modules/babel-core/index.js?{"presets":["react"]} didn't return a function "
- Can't perform a React state update on an unmounted component warning
- React meta tags not working for Facebook
- What's the correct pattern to change parent state inside a child state in React?
- Reactjs - Call function on startup of application with a functional component
- ReactJS - How to return a string from functional component?
- SetState with nested ternary expression
- how to display a random value from an array of objects in an React view
- How to add props to a grouped array?
- React Promise stuck on {Pending} Promise Status Fulfilled
- Why is this code giving a warning about functions not being valid as a React child?
- React set Route in Component function without Link
- using updated state in function
- React pass specific state to the Modal component on click
- Show/Hide Section in dropdown menu for Gatsby Site
- React website showing "Not secured" hosted through GoDaddy
- Error on OnBlur after using useReduce in React
- Hide a component in Login in react Routes
- React update lifecycle methods return same props for date
- React-Leaflet same marker in multiple Layers
- NodeInvocationException when trying to get data from localStorage in stateless React component