You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to migrate my NextJS site to AMP only but facing issues at the moment as the redux side of things doesn't work. For example, it appears that the 'getTrendingPosts' action was not dispatched.
index.js
import React, {useEffect} from 'react'
import {connect} from 'react-redux'
import HomePage from "../screens/main/home/HomePage";
export const config = {
amp: true,
}
const Index = props => {
return <HomePage/>
}
export default Index
HomePage.js
import {useEffect} from "react";
import {objectToArray} from "../../../utilities/utils";
import {getTrendingPosts} from "./HomeActions";
import {connect} from "react-redux";
import _ from 'lodash';
import NavBar from "../../../features/nav/NavBar";
import PostItem from "../../../features/post/PostItem";
const HomePage = props => {
useEffect(async () => {
if (_.isEmpty(props.trendingPosts)) {
props.getTrendingPosts(true)
}
}, [])
console.log('post', props.trendingPosts)
return (
<>
<NavBar/>
<main>
{!_.isEmpty(props.trendingPosts) &&
<PostItem key={props.trendingPosts[0].id} post={props.trendingPosts[0]}/>}
</main>
</>
)
}
const mapStateToProps = state => {
return {
trendingPosts: objectToArray(_.pick(state.posts, state.home.trendingPostIds)),
};
};
export default connect(mapStateToProps, {
getTrendingPosts,
})(HomePage);
The console.log line returns an empty array, while this is not the case when it is not on AMP. I have checked online but I can't seem to find a Redux + AMP template or example. Please can you assist me with the above.
This discussion was converted from issue #13544 on May 29, 2020 12:16.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
AMP does not work with Redux
I am trying to migrate my NextJS site to AMP only but facing issues at the moment as the redux side of things doesn't work. For example, it appears that the 'getTrendingPosts' action was not dispatched.
index.js
HomePage.js
The console.log line returns an empty array, while this is not the case when it is not on AMP. I have checked online but I can't seem to find a Redux + AMP template or example. Please can you assist me with the above.
Beta Was this translation helpful? Give feedback.
All reactions