Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于获取数据顺序问题 #1

Open
sbuteryd opened this issue Oct 6, 2019 · 0 comments
Open

关于获取数据顺序问题 #1

sbuteryd opened this issue Oct 6, 2019 · 0 comments
Labels
bug Something isn't working

Comments

@sbuteryd
Copy link
Owner

sbuteryd commented Oct 6, 2019


export function handleInitData(){
    return (dispatch)=>{
        return API.getInitialData().then(({tweets,users})=>{
            **dispatch(receiveTweets(tweets))**
            dispatch(receiveUsers(users))
            dispatch(authedUser(AUTHED_USERS))
        })
    }
}

1、如果一开始获取tweet、后面获取用户会报错,如下所示(users[tweet.author] 这个或报错的原因是要使用users 没有用户。

function mapStateToProps({tweets,users,authedUser},{tweetId}) {
    let tweet = tweets[tweetId]
    const parentTweet = tweet.replyingTo   === null  ? null:tweet.replyingTo

     console.log(users[tweet.author])
    return {
        authedUser,
        // tweetList:formatTweet(tweet,users[tweet.author],authedUser,parentTweet)
    }

解决方案:

export function handleInitData(){
    return (dispatch)=>{
        return API.getInitialData().then(({tweets,users})=>{
            **dispatch(receiveUsers(users))**
            dispatch(receiveTweets(tweets))
            dispatch(authedUser(AUTHED_USERS))
        })

    }
}


@sbuteryd sbuteryd added the bug Something isn't working label Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant