gpt4 book ai didi

javascript - Alt "connectToStores"在 React/Flux 应用程序中已弃用?

转载 作者:行者123 更新时间:2023-11-30 16:09:12 26 4
gpt4 key购买 nike

我正在通过教程使用 React 和 Flux 构建一个小型聊天应用程序,但是该教程似乎已经过时,因为它使用的是 Alt(与 Flux 一起使用)的方法,会引发以下错误:

无法解析模块“alt/utils/connectToStores”

...我相信它来自 @connectToStores 行。下面是我的代码。我调查了这个问题,似乎 Alt 被分解成更小的包,其中之一是 Alt-React(这完全让我难堪)。我的问题是,我怎样才能以最新的方式使用这种方法?

import React from 'react';
import mui from 'material-ui';
import MessageList from './MessageList.jsx';
import MessageBox from './MessageBox.jsx';
import Login from './Login.jsx';
import ChannelList from './ChannelList.jsx';
import connectToStores from 'alt/utils/connectToStores';
import ChatStore from '../stores/ChatStore';

// Material UI
import * as Colors from 'material-ui/lib/styles/colors';
import AppBar from 'material-ui/lib/app-bar';
import getMuiTheme from 'material-ui/lib/styles/getMuiTheme';

@connectToStores // es7 decorator with deprecated 'connectToStores'
class App extends React.Component {
constructor() {
super();
}

static getStores() {
return [ChatStore];
}

static getPropsFromStores() {
return ChatStore.getState();
}

static childContextTypes = {
muiTheme: React.PropTypes.object
}

getChildContext() {
return {
muiTheme: getMuiTheme({
primary1Color: Colors.blue500,
primary2Color: Colors.blue700,
primary3Color: Colors.blue100,
accent1Color: Colors.pink400
})
};
}

render() {
var view = <Login />;

if (this.props.user) {
view = (
<div>
<div id="content-container">
<ChannelList />
<MessageList />
</div>
<MessageBox />
</div>
);
}

return (
<div>
<AppBar title="Chat App"/>
{{view}}
</div>
);
}
}

export default App;

最佳答案

Alt Utils 库已全部移动到位于 https://github.com/altjs/utils 的单独包中

一旦安装

npm i --save-dev alt-utils

您可以使用教程所需的访问相同的库:

import connectToStores from 'alt-utils/lib/connectToStores';
import {decorate, bind, datasource} from 'alt-utils/lib/decorators';

关于javascript - Alt "connectToStores"在 React/Flux 应用程序中已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36526565/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com