Material-ui: @ material-ui / styles : 클래슀 ꡬ성 μš”μ†Œμ—μ„œμ˜ μ‚¬μš©?

에 λ§Œλ“  2019λ…„ 05μ›” 24일  Β·  17μ½”λ©˜νŠΈ  Β·  좜처: mui-org/material-ui

클래슀 ꡬ성 μš”μ†Œ λ‚΄μ—μ„œ 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.
docs question

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

λ‚΄κ°€ μ‚¬μš© 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);

λͺ¨λ“  17 λŒ“κΈ€

클래슀 ꡬ성 μš”μ†Œ λ‚΄μ—μ„œ 후크λ₯Ό μ‚¬μš©ν•  수 μ—†μŠ΅λ‹ˆλ‹€. κΈ°λŠ₯적인 ꡬ성 μš”μ†Œκ°€ ν•„μš”ν•˜κ±°λ‚˜ 더 높은 차수 ( 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λ₯Ό

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰