2016-06-07 2 views
0

Redux/React를 처음 사용하고 상태 객체에 대한 작업에 문제가 있습니다.Redux (기본)의 상태 객체 작업

나는 아래하는 index.js에 나의 상태를 초기화했지만 내 행동이 오류를

Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {text}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of ShowTweetComponent.

하는 index.js 여기

const initialState = { 
    text: 'test successful' 
} 

let store = createStore( 
    twitterApp,  
    initialState,  
    applyMiddleware( 
    thunkMiddleware 
) 
) 

console.log('1 - index.js loaded') 

render( 
    <Provider store={store}> 
     <App /> 
    </Provider>, 
    document.getElementById('LoadApp') 
) 

입니다 얻고있다

function getTweetData(json) { 
    return { 
    type: REQUEST_TWEETS, 
    tweet: json.status_text, 
    receivedAt: Date.now().toString() 
    } 
} 

function fetchTweets() { 

    return dispatch => { 
    return fetch(`/api/twitter`) 
     .then(response => response.json()) 
     .then(json => dispatch(getTweetData(json))) 
    } 


} 

export function fetchTweetsIfNeeded() { 
    return (dispatch, getState) => { 
    return dispatch(fetchTweets()) 
    } 
} 
당신은 알려 주시기 바랍니다 필요한 모든 추가 정보가 있으면

그리고 여기 내 감속기에게

const displayData = (state = [], action) => { 

    switch (action.type) { 

    case REQUEST_TWEETS: 
     return [ 
     ...state, 
     { 
      text: action.tweet 
     } 
     ] 

    default: 
     return state 
    } 
} 

을합니다. exampleState = 'this is my message!'

UPDATE 작업 할 때 나는 단지 그것을 작동시킬 수 있습니다 여기 당신은 당신의 REDUX 상태와 this.props.children을 overwritting있는 REPO (물건을 반응에 대한 클라이언트 폴더 참조) https://github.com/jaegerbombb/twitter-api-test

+3

다른 이름으로 children 키를 변경할 수 주 또는 REDUX과는 아무 상관이 없습니다. 이것은 React 에러이며, 대부분 App에있을 것이다. 그걸 보여줄 수 있니? – ZekeDroid

+2

구체적으로 보이는'ShowTweetComponent' –

+0

물론, 설명에 링크를 추가했습니다. 더 많은 정보를 원한다면 알려주세요. 난 이미 오류 참조를 보았지만 내 자신의 문제를 이해할 수 없었다. – darkace

답변

1

이다 (당신의 twitterContainer.js에서). 나는 이것이 좋은 생각인지 확신하지 못한다. 반응은 childrennode 일 것으로 예상되지만, 귀하의 twitterApp 감속기에서 배열을 얻고 있습니다.

당신의 코드를 들어, 당신이 당신 twitterContainer.jstwitterComponent.js

관련 문제