I have the reducer:
const INITIAL_STATE = {
campaign_dates: {
dt_start: '',
dt_end: '',
},
I am submiting my form and them send an action to save the data into redux:
function onSubmit(data) {
dispatch(addCampaignDatesAction(data))
}
So far so good, I'm able to save the data, but how can I load it in my form?
In my component where my form is, I tried something like this:
const getCampaignDatesFromState = useSelector(
state => state.createCampaign.campaign_dates,
)
const [startDate, setStartDate] = useState(getCampaignDatesFromState.dt_start !== '' ? new Date(getCampaignDatesFromState.dt_start) : '')
const [endDate, setEndDate] = useState(getCampaignDatesFromState !== '' ? new Date(getCampaignDatesFromState.dt_end) : '')
But I'm getting "Invalid time value at format" error (my start and end date inputs is from react-datepicker)
What is the proper way to load redux data into your form?
const startCampaignDate = useSelector( state => state.createCampaign.campaign_dates.dt_start, )its working now. Thanks @SuleymanSah