M
M
MSGroup2021-05-10 16:56:14
React
MSGroup, 2021-05-10 16:56:14

How to fix Uncaught Error: Objects are not valid as a React child?

There is the following code:

const initialState = {
  startDate: null,
  endDate: null,
  focusedInput: null,
}

function reducer(state, action) {
  switch (action.type) {
    case 'focusChange':
      return {...state, focusedInput: action.payload}
    case 'dateChange':
      return action.payload
    default:
      throw new Error()
  }
}

function DateTimePicker1() {
  const [state, dispatch] = useReducer(reducer, initialState)



    return (
        <div>
            <DateRangeInput
              onDatesChange={data => dispatch({type: 'dateChange', payload: data})}
              onFocusChange={focusedInput => dispatch({type: 'focusChange', payload: focusedInput})}
              startDate={state.startDate} // Date or null
              endDate={state.endDate} // Date or null
              focusedInput={state.focusedInput} // START_DATE, END_DATE or null
            />
            <h1>endDate={state.endDate}</h1>

        </div>
  )
}

export default DateTimePicker1;

The whole problem lies in the output . I'm pretty new to this and I can't seem to figure out what's wrong here. <h1>endDate={state.endDate}</h1>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question