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

How to set default start and end date #81

Closed
sommesh opened this issue Apr 27, 2020 · 1 comment
Closed

How to set default start and end date #81

sommesh opened this issue Apr 27, 2020 · 1 comment

Comments

@sommesh
Copy link

sommesh commented Apr 27, 2020

<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
/>

In DateRangeInput is there any way to set default startDate and endDate when the UI is rendered first?

And how shall we disable the edit option?

https://prnt.sc/s6v96u

@tresko
Copy link
Collaborator

tresko commented Jun 9, 2020

Here is an example:

const initialState = {
  startDate: new Date(), // Default start date
  endDate: new Date(), // Default end date
  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();
  }
}

...
  const [state, dispatch] = useReducer(reducer, initialState);

@tresko tresko closed this as completed Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants