Open Erwan2005 opened 2 years ago
Yes same issue. But please reformate your code example.
same issue, in my case I have around 5 pages, but it only load first 2 pages, don't know why the rest 3 pages can't be loaded
I am using a different infinite scroll component now https://github.com/danbovey/react-infinite-scroller. That seems to be working fine. In my case DOM scroll events
code is working
same issue and I set scrollableTarget="scrollableDiv"
in div id=scrollableDiv its worked!
<div id="scrollableDiv" className={styles.noticeBody}>
<InfiniteScroll
dataLength={remindList.length}
next={loadMoreData}
hasMore={remindList.length < remindListTotal}
loader={<Skeleton avatar paragraph={{rows: 1}} active/>}
endMessage={null}
scrollableTarget="scrollableDiv"
>
same issue, only load first page and second page, then it will not loading third page onwards
any solution ?
https://github.com/ankeetmaini/react-infinite-scroll-component/issues/274#issuecomment-846626389 this answer fixed my issue
Thanks @orahul1 You saved me. That part of the documentation was a bit fuzzy in the wording.
Set dataLength={items.length}
instead of total items to be loaded.
I solved it this way by rewriting his method, if next error
import InfiniteScroll, { Props } from "react-infinite-scroll-component";
export default class MyInfiniteScroll extends InfiniteScroll {
componentDidUpdate(prevProps: Props) {
prevProps.dataLength = 0;
super.componentDidUpdate(prevProps);
}
}
I'm training to develop my little app with react, and I'm stuck in infinite scrolling I'm using react infinite scroll components, it calls the fetchmoredata function but just once, how to fix this kind of problem with my code below
`import React, {Fragment} from 'react' import { Card,CardHeader,CardActionArea, CardMedia,CardContent, Typography, CardActions,withStyles, Avatar,IconButton,Collapse,Button, InputAdornment,FormControl,Input,List, ListItem,ListItemText,ListItemAvatar, CircularProgress,InputBase,Divider,Box } from '@material-ui/core'; import { MoreVert,FavoriteBorder,Share,Telegram,PermMedia,Room,EmojiEmotions,Favorite } from '@material-ui/icons'; import {format} from 'timeago.js'; import { Link } from 'react-router-dom'; import NumericLabel from 'react-pretty-numbers'; import axios from 'axios'; import { AuthContext } from "../context/AuthContext"; import InfiniteScroll from 'react-infinite-scroll-component'; import _ from 'lodash';
const useStyles = theme => ({ media:{ height: 250,
}, card:{ marginBottom: theme.spacing(1), boxShadow: 'none', backgroundColor: '#424242', }, tile:{ height: theme.spacing(40), display: "flex", flexDirection: "column", margin: 5,
}, name:{ fontSize: 16, fontWeight: 500, color: "#848484", }, card_action:{ display: "flex", justifyContent: "space-between", borderTop: '1px solid #484848', }, card_header:{ backgroundColor: "#424242", }, item:{ display: "flex", alignItems: "center", spacing: theme.spacing(1), color: "#848484", }, link:{ display: "flex", textDecoration: "none", color: "#848484", textTransform: 'capitalize', }, share:{ backgroundColor: '#424242', marginBottom: theme.spacing(1), padding: theme.spacing(2), borderRadius: theme.spacing(1), //boxShadow: '0px 1px 7px 0px rgba(0,0,0,0.37)', }, share_top:{ display: 'flex', alignItems: 'center', }, shareBottom:{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', paddingTop: '10px' }, options:{ display: 'flex', marginLeft: theme.spacing(6.2), }, option:{ display: 'flex', alignItems: 'center',
}, shareIcon:{ fontSize: '18px', marginRight: '3px', }, shareOptionText:{ fontSize: '12px', fontWeight: '500', color: "#848484",
}, shareButton:{ textTransform: 'none', background: 'green', color: 'white', fontWeight: '500', "&:hover": { background: 'green', fontWeight: 'bold', },
}, });
export class Post extends React.Component { static contextType = AuthContext; constructor(props){ super(props); this.refImg = React.createRef(); this.state={ expanded:false, anchorElP: '', comment: '', share: '', comments: [], publication: [], users: [], current: [], next_url: 'http://127.0.0.1:8000/userapp/publication/', count: null, more_exist: true, image: '', liked: false, like: [], };
};
handleExpandClick = (id) => { this.setState({ [
expanded_${id}
]: .isUndefined(this.state[`expanded${id}])?true:!this.state[
expanded_${id}`] }); };handleProfileMenuOpenP = (event) => { this.setState({anchorElP:event.currentTarget}); };
handleMenuCloseP = () => { this.setState({anchorElP:null});
}; getPub = async() =>{ await axios({ method: 'get', url: this.state.next_url, headers:{ Authorization:
Token ${this.context.user.token}
, }, }).then(res =>{ var has_more = false if(res.data.next){ has_more = true } this.setState({ next_url: res.data.next, count: res.data.count, publication: res.data.results, more_exist: has_more, }) }) }; getLike = async() =>{ let data = await axios.get('http://127.0.0.1:8000/userapp/like/') .then(({data})=>data) this.setState({like: data}) };getCom = async() =>{ let data = await axios({ method: 'get', url: 'http://127.0.0.1:8000/userapp/comment/', }).then(({data}) => data) this.setState({comments: data}) }; getUser = async() =>{ let data = await axios({ method: 'get', url: 'http://127.0.0.1:8000/userapp/users/', }).then(({data}) => data) this.setState({users: data}) }; getCurrentUser = async() =>{ let data = await axios({ method: 'get', url:
http://127.0.0.1:8000/userapp/users/${this.context.user.id}/
,};
btnComment = async(content,id_post) => { let author = parseInt(this.context.user.id, 10) let post_connected = parseInt(id_post, 10) const contents = {content:content,author:author,post_connected:post_connected} let data = await axios.post('http://127.0.0.1:8000/userapp/comment/',contents) .then(({data}) => data) this.setState({comments: this.state.comments.concat(data)}) this.setState({comment:''})
btnShare = async()=>{ let author = parseInt(this.context.user.id, 10) const contents = {user:author,message: this.state.share,image:this.state.image} await axios.post('http://127.0.0.1:8000/userapp/publication/',contents,{ headers:{ Authorization:
Token ${this.context.user.token}
} }).then(res=>{ console.log(res) }) this.setState({share:'',image:''}) };fetchData = async() =>{ await axios({ method: 'get', url: this.state.next_url, headers:{ Authorization:
Token ${this.context.user.token}
, }, }).then(res =>{ var has_more = false if(res.data.next){ has_more = true } this.setState({ next_url: res.data.next, count: res.data.count, publication: this.state.publication.concat(res.data.results), more_exist: has_more, }) console.log(this.state.count) }) };imageHandler = async (e) => {
convertBase64 = (file) => { return new Promise((resolve, reject) => { const fileReader = new FileReader(); fileReader.readAsDataURL(file);
checkLiked = (userId,postId) =>{ if (this.state.like.filter(item=> item.author == userId && item.post_connected === postId).length == 0) return false else return true };
dlt =async(id)=>{ await axios.delete(
http://127.0.0.1:8000/userapp/like/${id}
) this.getLike() };dltLike = (userId,postId)=>{ this.state.like.filter(item=> item.author == userId && item.post_connected === postId).map(cheked=>(this.dlt(cheked.id))) };
postLike = async(author,post_connected) =>{ let data = await axios.post('http://127.0.0.1:8000/userapp/like/',{author,post_connected}) .then(({data})=>data) this.setState({like: this.state.like.concat(data)}) };
componentDidMount(){ this.getUser() this.getPub() this.getCom() this.getCurrentUser() this.getLike() }; render() { const { classes } = this.props; return ( <InfiniteScroll pageStart={0} dataLength={this.state.more_exist} //This is important field to render the next data next={this.fetchData} hasMore={this.state.more_exist} loader={
Loinding ...
} }
export default withStyles(useStyles)(Post);`