鍍金池/ 問答/HTML5  HTML/ React state更新第三方庫(kù)未重新渲染

React state更新第三方庫(kù)未重新渲染

我需要將js定義的一些style傳到一個(gè)第三方庫(kù)里,但是貌似state更新后并沒有重新渲染樣式,我確定組件是更新了,但是這個(gè)第三方庫(kù)傳進(jìn)去的樣式未更新,有人幫忙解決下嗎?

代碼如下

class Console extends React.Component {

  getConsoleFeedStyle(theme) {
    const style = {};
    switch (theme) {
      case 'light':
        return Object.assign(style, a);
      case 'dark':
        return Object.assign(style, b);
      case 'contrast':
        return Object.assign(style, c);
      default:
        return '';
    }
  }


render() {
    return (
        <div>
          {this.props.consoleEvents.map((consoleEvent) => {
            const { theme } = this.props;
            return (
              <div key={consoleEvent.id}>
                <ConsoleFeed
                  styles={this.getConsoleFeedStyle(theme)}
                  logs={Array.of(consoleEvent)}
                />
              </div>
            );
          })}
        </div>
      </div>
    );
  }
}
回答
編輯回答
柚稚

先在 getConsoleFeedStyle 里面debug看看運(yùn)行了沒,在看看 a,b,c的key是否是正確的樣式

2018年7月24日 22:31
編輯回答
幼梔

在getConsoleStyle函數(shù)和render函數(shù)里加入console,并在getConsoleStyle函數(shù)里console參數(shù),看運(yùn)行邏輯是否和你期望的一致

2017年8月22日 17:33
編輯回答
淚染裳

這個(gè)是個(gè)組件,又不是div。。。
你style傳過去,他組件里又不用,你傳過去有什么用

2017年12月16日 19:14