Bài 3: Cấu hình scss vào dự án

1. Tạo file GlobalStyles component 1.1 Tạo file src/components/GlobalStyles/index.tsx import './GlobalStyles.scss'; type Props = { children: JSX.Element; }; function GlobalStyles({ children }: Props) { return children; } export default GlobalStyles; 1.2 Tạo file src/components/GlobalStyles/GlobalStyles.scss @import 'normalize.css'; @import url('https://fonts.googleapis.com/css2?family=Roboto:[email protected];400;500;700;900&display=swap'); :root { --primary: #fe2c55; } html { font-size: 62.5%; } body { font-family: 'Roboto', sans-serif; font-size: 1.6rem;

1. Tạo file GlobalStyles component

1.1 Tạo file src/components/GlobalStyles/index.tsx

import './GlobalStyles.scss';

type Props = {
    children: JSX.Element;
};

function GlobalStyles({ children }: Props) {
    return children;
}

export default GlobalStyles;

1.2 Tạo file src/components/GlobalStyles/GlobalStyles.scss

@import 'normalize.css';
@import url('https://fonts.googleapis.com/css2?family=Roboto:[email protected];400;500;700;900&display=swap');

:root {
    --primary: #fe2c55;
}

html {
    font-size: 62.5%;
}

body {
    font-family: 'Roboto', sans-serif;
    font-size: 1.6rem;
    line-height: 1.5;
    text-rendering: optimizespeed;
}

2. Cài thư viện reset css và scss

yarn add --save normalize.css
yarn add sass

3. Sửa lại file index.tsx

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from '~/App';
import GlobalStyles from '~/components/GlobalStyles';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
    <React.StrictMode>
        <GlobalStyles>
            <App />
        </GlobalStyles>
    </React.StrictMode>,
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

4. Xoá các file ko cần thiết như index.css. logo, app.css

Nguồn: viblo.asia

Bài viết liên quan

Thay đổi Package Name của Android Studio dể dàng với plugin APR

Nếu bạn đang gặp khó khăn hoặc bế tắc trong việc thay đổi package name trong And

Lỗi không Update Meta_Value Khi thay thế hình ảnh cũ bằng hình ảnh mới trong WordPress

Mã dưới đây hoạt động tốt có 1 lỗi không update được postmeta ” meta_key=

Bài 1 – React Native DevOps các khái niệm và các cài đặt căn bản

Hướng dẫn setup jenkins agent để bắt đầu build mobile bằng jenkins cho devloper an t

Chuyển đổi từ monolith sang microservices qua ví dụ

1. Why microservices? Microservices là kiến trúc hệ thống phần mềm hướng dịch vụ,