gpt4 book ai didi

reactjs - CSSTransitionGroup 和 Redux Connect 的正确使用方法

转载 作者:行者123 更新时间:2023-12-03 13:31:28 25 4
gpt4 key购买 nike

我正在尝试向组件添加一些动画样式,并努力找出问题所在。这是一个带有 connect() 和 CSSTransitionGroup 的简单组件(DOM 中其他位置的不同组件最终将用于触发打开我的灯箱组件,Redux 将用于在它们之间共享状态,以防您想知道为什么这是一个要求) :

LightboxPresentation.js:

import React, { Component } from 'react';
import { CSSTransitionGroup } from 'react-transition-group';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as actionCreators from '../actions/actionCreators';

class LightboxPresentation extends Component {
render() {
return (
<div>
<CSSTransitionGroup
transitionName="lightbox"
transitionEnterTimeout={500}
transitionLeaveTimeout={500}>
{this.renderPage()}
</CSSTransitionGroup>
</div>
)
}
renderPage() {
return (
<div key={'lightbox-module'}>Some test HTML</div>
);
}
}

const mapStateToProps = (state) => {
return {
showLightbox: state.showLightbox,
itemsShowLightbox: state.itemsShowLightbox,
};
};
const mapDispatchToProps = (dispatch) => {
return bindActionCreators(actionCreators, dispatch);
};
export default connect(mapStateToProps, mapDispatchToProps)(LightboxPresentation);

这是调用上述组件的代码:

App.js:

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import configureStore from './store/configureStore';

import ItemList from './components/ItemList';
import LightboxPresentation from './components/LightboxPresentation';

const initialState = { itemFilter: 'featured' }

const store = configureStore(initialState);

render(
<Provider store={store}>
<LightboxPresentation />
</Provider>,
document.getElementById('lightbox')
);

但是我在控制台中收到以下错误:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of `LightboxPresentation`.
in LightboxPresentation
in Connect(LightboxPresentation)
in Provider

如果我从 renderPage 调用周围删除 block ,则 renderPage 的输出将不会出现错误。仅添加转换 block 会导致错误。据我所知 import { CSSTransitionGroup } 是正确的,这就是他们在 documentatio 中的做法。 n (虽然我确实尝试过不带花括号但仍然没有运气)。

我做错了什么吗?我花了一些时间尝试不同的事情和谷歌搜索,但到目前为止都没有乐趣。

最佳答案

您使用的是 React-transition-group 2+ 版本吗?版本 2 之后不再有 CSSTransitionGroup。如果您希望代码按原样工作,请尝试执行 npm install --save react-transition-group@1.2.0 进行恢复。

如果您想使用新版本,请尝试使用 These Docs 中找到的较新 API .

关于reactjs - CSSTransitionGroup 和 Redux Connect 的正确使用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46299729/

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