React? CSS-in-JS
CSS-in-JS? CSS ???? JavaScript ?? ?? ???? ?????. ?? ?? ???? JavaScript ??? ???? CSS ??? ??? ? ??? React ?????? ??? ??? ?? ?? ???? ???? ?? ??? ?????. ? ??? ???? ?? ?????? ?? ?? ????? ??? ???? ???? ?? ????? ???? ??? ?????.
React?? CSS-in-JS? ???? ???? ?? ?? ??? ???? ???? ???? ?? ?? ???? ??? ? ????. Styled Components, Emotion, JSS
? ? ??? ???? ?? ?? ?????? ????.CSS-in-JS? ?? ??
-
??? ??? ???
: CSS-in-JS? ???? ??? ?? ?? ??? ???? ?? CSS ?? ???? ?????. ??? ?? ???? ?? ?? ?? ??? ????? ??????? ? ?? ?? ??? ? ????. -
?? ????
: CSS-in-JS? ???? JavaScript ??, ?? ? ??? ???? ?? ?? ??? ?? ???? ???? ?? ??? ? ????. ?? ?? ??? ?? ?? ??? ??? ? ????. -
?? ?? ?? ????
: ???? ?? ?? ??? ?? ????? ?? ??? ???????? ????? ? ????. ?? ?? ?? ????? ?? ??? ??? ?????? ???????. -
?? ???? ???
: Styled Components ? Emotion? ?? ?? CSS-in-JS ?????? ???? ???? ???? ???? ???? ? ???? ?????. -
??
: CSS-in-JS? ???? ?? ??? ? ?? ?? ? ????. ??? ???? ? ???, ?????? ? ?? ?? ???? ???? ?? ?? ??? ???? ??? ? ????.
?? CSS-in-JS ?????
1. ???? ??? ?? ??
??? ?? ??
? CSS-in-JS?? ?? ?? ?? ????? ? ?????. ?? ?? JavaScript ?? ?? ?? CSS ??? ??? ? ??? ??? ?? ?? ??? ?????.?: ???? ??? ?? ?? ??
npm install styled-components
import React from 'react'; import styled from 'styled-components'; // Create a styled component const Button = styled.button` background-color: ${(props) => (props.primary ? 'blue' : 'gray')}; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; &:hover { opacity: 0.8; } `; const App = () => { return ( <div> <Button primary>Primary Button</Button> <Button>Secondary Button</Button> </div> ); }; export default App;
??:
- styled.button? ?? ?? ??? ???? ??? ? ??? Styled ?? ???? ???? ?????.
- ???? ??? ?? ????? ?????. ?, ???? ?? ???? ??? ?? ????.
- ?? ??? ??? ???? ???? ???? ? ?????.
2. ??
Emotion? ??? ???? ???? ???? ? ?? ?? ?? CSS-in-JS ????????. ??? ?? ??? ????? ?? ??? ? ?? ? ???? ?? ? ?? ??? ?? ? ?? ?? ??? ????.
?: ?? ??
npm install @emotion/react @emotion/styled
/** @jsxImportSource @emotion/react */ import { css } from '@emotion/react'; import styled from '@emotion/styled'; const buttonStyle = (primary) => css` background-color: ${primary ? 'blue' : 'gray'}; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; &:hover { opacity: 0.8; } `; const Button = styled.button` ${props => buttonStyle(props.primary)} `; const App = () => { return ( <div> <Button primary>Primary Button</Button> <Button>Secondary Button</Button> </div> ); }; export default App;
??:
- Emotion? CSS ??? ??? ??? ???? ? ????, ??? ??? ??? API? ?? ?? ??? ??? ? ????.
- Emotion? ???? ??? ???? JavaScript ??? ?? ???? ???? ??? ? ????.
3. JSS(?????? ??? ??)
JSS? JavaScript? ???? CSS? ??? ? ??? ?? ? ?? CSS-in-JS ????????. ??? ?? ?? ? ?? ??? ??? ?? ??? ?? ???? ?? ???? ??? ? ????.
?: JSS ??
npm install jss react-jss
import React from 'react'; import { createUseStyles } from 'react-jss'; const useStyles = createUseStyles({ button: { backgroundColor: (props) => (props.primary ? 'blue' : 'gray'), color: 'white', padding: '10px 20px', border: 'none', borderRadius: '5px', cursor: 'pointer', '&:hover': { opacity: 0.8, }, }, }); const Button = (props) => { const classes = useStyles(props); return <button className={classes.button}>{props.children}</button>; }; const App = () => { return ( <div> <Button primary>Primary Button</Button> <Button>Secondary Button</Button> </div> ); }; export default App;
??:
- createUseStyles? ???? ???? React-jss?? ???? ?????.
- useStyles ??? props? ???? ??? ??? ??? ?????.
- ? ??? ?? ??? ??? ??? ???? ?? ???? ?????.
CSS-in-JS? ??
CSS-in-JS?? ?? ??? ??? ??? ??? ????.
- ?? ????: CSS-in-JS ?????? ?? ?? ???? ?? ??? ??????? ?? ?? ????? ??? ? ????.
- ?? ?? ??: ???? JavaScript ??? ?? ??? ????? JavaScript ??? ??? ?? ? ????.
- ?? ??: ?? CSS ?? ???? ?? ????(?: Sass)? ??? ???? ?? CSS-in-JS? ????? ?? ??? ??? ? ????.
- ????? ??: ?? ???? ??? ??? ???? ??? ???? ?? ????? ?? ??? ????? ?????.
CSS-in-JS ?? ??
- ?? ??: CSS-in-JS ??????? ???? ?? ??? ???? ?? ?? ???(?: ??, ??)? ?????.
- ??? ?? ??: ??? ?? ?? ?? JSS? ???? ??? ??? ??? ?? ?? ??? ???? ?? ???? ?? ???? ?? ?????.
- ?? ??? ??: ??? ?? ???? ??? ???? ??? ?? ? ???? ?? ???? ???? ?????.
- ??? ?? ??: Babel? ?? ??? ??? CSS? ????? ? CSS-in-JS ?????? ??? ????? ? ??? ? ? ????.
??
CSS-in-JS? JavaScript? CSS? ??? ??? ???? React ?????? ???? ???? ???? ?? ?????. ??? ?? ??, Emotion ?? JSS? ?? ?????? ???? JavaScript ?? ?? ???? ???? ?????? ???, ?? ? ?? ???? ???? ? ????. ??? ?? ??? ????????? CSS-in-JS ??? ???? ?? ?? ??? ??? ??? ?? ?????.
? ??? CSS-in-JS: React ??????? ?? ???? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

JavaScript? ??? ?? ????? ??? ?? ??? ??? ?? ?? ?? ????? ?? ???? ???? ?????. ??? ?? ???? ?? ??? ?? ??? ???? ???? ?? ?? ???? ???? ?????. ?? ??, ??? ? ?? ???? ??? (? : ??? null? ??) ?? ??? ????? ??????. ??? ??? ???? ??? ??? ????. closure?? ?? ??? ?? ??; ? ??? ??? ?? ?? ???? ?? ???? ????. V8 ??? ?? ???, ?? ??, ??/?? ???? ?? ??? ?? ??? ??? ????? ?? ??? ?? ??? ????. ?? ?? ???? ??? ??? ??? ??? ???? ????? ?? ?? ???? ?? ???????.

Node.js?? HTTP ??? ???? ? ?? ???? ??? ????. 1. ?? ????? ????? ??? ??? ? ?? ????? ?? ?? ? https.get () ??? ?? ??? ??? ? ?? ????? ?? ??? ?????. 2.axios? ??? ???? ? ?? ??????. ??? ??? ??? ??? ??? ??? ???/???, ?? JSON ??, ???? ?? ?????. ??? ?? ??? ????? ?? ????. 3. ?? ??? ??? ??? ??? ???? ???? ??? ??? ???? ?????.

JavaScript ??? ??? ?? ?? ? ?? ???? ????. ?? ???? ???, ??, ??, ?, ???? ?? ? ??? ?????. ?? ????? ?? ?? ? ? ??? ????? ?? ??? ??? ????. ??, ?? ? ??? ?? ?? ??? ??? ??? ???? ??? ??? ???? ??? ?? ??? ????. ?? ? ????? ??? ???? ? ??? ? ??? TypeofNull? ??? ?????? ??? ? ????. ? ? ?? ??? ???? ?????? ????? ???? ??? ???? ? ??? ? ? ????.

?? JavaScript ??? ??? ??? ?????? ?? ??? ?? ?? ??? ?? ???? ????. 1. ??? ???? ???? ?? ??? ?? ? ? ???? ??? ??? ?? ? ?? ????? ?????. 2. Angular? ?????? ??? ?? ???? ? ?? ?? ??? ??? ??? ???? ?????. 3. VUE? ???? ?? ??? ???? ?? ?? ??? ?????. ?? ?? ?? ??, ? ??, ???? ???? ? SSR? ???? ??? ??? ??? ???? ? ??? ?????. ???, ??? ??? ??? ????? ????. ??? ??? ??? ??? ?? ????.

?????, JavaScript ???! ?? ? JavaScript ??? ?? ?? ?????! ?? ?? ??? ??? ??? ? ????. Deno?? Oracle? ?? ??, ??? JavaScript ?? ??? ????, Google Chrome ???? ? ??? ??? ???? ?????. ?????! Deno Oracle? "JavaScript"??? ????? Oracle? ?? ??? ??? ??????. Node.js? Deno? ??? ? Ryan Dahl? ??? ?????? ???? ????? JavaScript? ??? ???? Oracle? ????? ???? ?????.

iife (?? invokedfunctionexpression)? ?? ??? ???? ?? ????? ??? ???? ?? ??? ????? ?? ??? ? ?????. ??? ?? ?? ??? ???? ? ?? ??? ??? ?? (function () {/code/}) ();. ?? ???? ??? ?????. 1. ?? ??? ??? ?? ???? ?? ??? ??? ?????. 2. ?? ??? ??? ???? ?? ?? ??? ????. 3. ?? ?? ??? ????? ?? ???? ???????? ?? ? ??. ???? ?? ???? ?? ??? ES6 ??? ??? ??? ?? ? ??? ????? ??? ? ???? ???????.

??? JavaScript?? ??? ??? ?????? ?? ???????. ?? ??, ?? ?? ? ??? ??? ?? ????? ????? ?????. 1. ?? ??? ??? ????? ???? ??. ()? ?? ??? ??? ?????. ?. ()? ?? ??? ?? ??? ??? ?? ? ? ????. 2. ?? ??? .catch ()? ???? ?? ??? ??? ?? ??? ??????, ??? ???? ???? ????? ??? ? ????. 3. Promise.all ()? ?? ????? (?? ?? ?? ? ??????? ??), Promise.Race () (? ?? ??? ?? ?) ? Promise.AllSettled () (?? ??? ???? ??)

Cacheapi? ?????? ?? ???? ??? ???? ???, ?? ??? ??? ?? ???? ? ??? ?? ? ???? ??? ??????. 1. ???? ????, ??? ??, ?? ?? ?? ???? ???? ??? ? ????. 2. ??? ?? ?? ??? ?? ? ? ????. 3. ?? ?? ?? ?? ?? ??? ??? ?? ?????. 4. ??? ???? ?? ?? ???? ?? ?? ?? ?? ?? ???? ?? ?? ??? ??? ? ????. 5. ?? ???? ??, ??? ??? ? ??? ??, ?? ??? ? ?? ???? ???? ???? ? ?? ?????. 6.?? ??? ?? ?? ?? ??, ???? ?? ? HTTP ?? ????? ?????? ???????.
