ν΄λμ€ κ΅¬μ± μμ λ΄μμ makeStyles
APIλ₯Ό μ΄λ»κ² μ¬μ©ν©λκΉ? μ€λͺ
μ μλ ν¨μ κ΅¬μ± μμμ μλ§ λμ μμ΅λλ€.
ν΄λμ€ κ΅¬μ± μμμ render
λ©μλ λ΄μμ μ΄κ²μ μ¬μ©νλ €κ³ νλ©΄ λ€μ μ€λ₯κ° λ°μν©λλ€.
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
ν΄λμ€ κ΅¬μ± μμ λ΄μμ νν¬λ₯Ό μ¬μ©ν μ μμ΅λλ€. κΈ°λ₯μ μΈ κ΅¬μ± μμκ° νμνκ±°λ λ λμ μ°¨μ ( withStyles
)λ₯Ό μ¬μ©ν΄μΌν©λλ€.
λ§κ°νκ² μ΅λλ€. λΉμ·ν λ³΄κ³ μκ° λ³΄μ΄λ©΄ λ¬Έμνν΄μΌνλ€κ³ μκ°ν©λλ€.
@oliviertassinari :νμ§λ§ μ±μ΄ ν΄λμ€λ‘ μ μΈλλ©΄ μ΄λ»κ²ν΄μΌνλμ?
μ±μλ μν λ° κΈ°ν κΈ°λ₯μ΄ μκΈ° λλ¬Έμ
λλ€.
@ Angelk90 μμ κ΅¬μ± μμ API : https://github.com/mui-org/material-ui/issues/15820#issuecomment -495480040 ( withStyles
)λ₯Ό μ¬μ©ν΄μΌν©λλ€.
λ¬Έμμ λ°λ₯΄λ©΄ withStyles
api μ¬μ© μμ λ μ¬μ ν ν¨μ κ΅¬μ± μμμ
λλ€.
https://material-ui.com/styles/basics/
κ·Έκ² λ΄κ° λΉμ μ λλ΅μ λ°λνλ₯Ό λμ§ μ΄μ μ λλ€.
μλ
νμΈμ.
HOCμμ makeStylesλ₯Ό μ΄λ»κ² μ¬μ©ν μ μμ΅λκΉ?
λ΄ μ¬μ© μ¬λ‘μ λ°λΌ μ€νμΌμ λ¨Έν°λ¦¬μΌ ν
λ§ κ°μ²΄κ° νμν©λλ€.
@ ghosh-jaideepμ΄ μ μνλ―μ΄,
λ€μκ³Ό κ°μ ν
λ§ μ νΈλ¦¬ν°λ₯Ό μ¬μ©νλ λ°©λ² :
[theme.breakpoints.up("md")]: {
paddingLeft: theme.spacing(2),
paddingTop: theme.spacing(2)
}
ν΄λμ€ κ΅¬μ± μμ λ΄λΆ?
κ°μ¬
λ΄κ° μ¬μ© withStyles
λμ makeStyle
κ³Ό κ°μ΄ ...
import React from 'react';
import { withStyles } from '@material-ui/core/styles';
const styles = (theme) => ({
fab: {
position: 'fixed',
bottom: theme.spacing(2),
right: theme.spacing(2),
},
});
class LoginComponent extends React?Component {
render() {
const { classes } = this.props;
/** your UI components... */
}
}
export default withStyles(syles)(LoginComponent);
@ Ess-Soft λΆλͺ¨ κ΅¬μ± μμμμ LoginComponent
λ μ΄λ»κ² λ λλ§λ©λκΉ?
ThemeProvider
μ μ¬μ© νμ΅λκΉ?μμ μ»΄ν¬λνΈμ μ½λ μ€ λν«μ 곡μ νλ©΄ λ μ μ©ν©λλ€.
@ Ess-Softμ λμΌν μμ
μ μννκ³ withStyles μ μ widthThemeλ₯Ό μΆκ°νμ΅λλ€.
withTheme(withStyles(useStyles)(LoginComponent ))
κ·Έλ¬λ©΄ render
λ΄λΆμμλ theme
μ¬μ©ν μ μμ΅λλ€.
λκ΅°κ° μ€νμΌλ‘ μ€λͺ ν μ μμ΅λκΉ? μμ§ν μ΄λ° κ±Έ 보면 γ γ γ γ γ γ γ γ γ γ γ γ γ γ γ μ€λ 3 μκ° λμ κ²μνκ³ λ΅μ μ°Ύκ³ λμ μ΄κ²μ μ°Ύμμ΅λλ€.
@ xtianus79 μ΄ APIλ https://material-ui.com/styles/basics/#higher -order -component-api ν΄λμ€ κ΅¬μ± μμμμλ μλν©λλ€.
@oliviertassinari 그리λλ‘ κ·Έ μλ₯Ό 보μ¬μ€ μ μμ΅λκΉ? γ γ κ·Έκ² λ΄κ°νλ €λ μΌμ΄κ³ λ°λ‘ κ±°κΈ°μ κ°ν μμ΄μ. λλ makeStylesμ createStylesλ₯Ό μ¬μ©νκ³ μλλ° ν¨μμμ΄ μ΄λ»κ² ν μ μλμ§ μ μ μμ΅λκΉ? λμ μ£Όμ€ μ μλμ?
@ xtianus79 StackOverflowμμ λ λ§μ λμλ§μ μ°Ύμ μ μμ΅λλ€.
@oliviertassinari λ νΉμ λ¬Έμ μ μ¬μ© μ¬λ‘μ λν΄ μ λͺ¨λ₯΄κ² μ΅λλ€.
μ. μ¬μ ν https://material-ui.com/styles/basics/#higher -order-component-apiκ° 'theme'μ¬μ© λ°©λ²μ λλ΅νμ§ μμ΅λκΉ? νν¬κ°μλ κΈ°λ₯μ κ΅¬μ± μμ λ§ μ§μνλ μ΄μ λ 무μμ λκΉ? μ¬λλ€μ λ κ±°μ μ½λλ₯Ό κ°μ§κ³ μκ±°λ ν΄λμ€ κΈ°λ° κ΅¬μ± μμκ° νμν©λλ€.
@DewangS withTheme()
API : https://material-ui.com/styles/api/#withtheme -component-componentλ₯Ό
κ°μ₯ μ μ©ν λκΈ
λ΄κ° μ¬μ©
withStyles
λμmakeStyle
κ³Ό κ°μ΄ ...