2

I have following code:

https://codesandbox.io/s/react-datepicerhook-u2vv1

As you can see there is a working date picker and a none working date picker. The two date pickers are very similar so I would like to make a new component that just takes the parameter as name. However there is something in my state that goes wrong on the one I denormalized. Any pointers why and how to solve it?

Thomas Segato
  • 4,567
  • 11
  • 55
  • 104
  • Sure? It is not like I have code that is working and would like a review. But code that does not work and need to know how to solve it? – Thomas Segato Apr 02 '20 at 14:39

1 Answers1

1

You bound one more layer of arrow function, so add one more () when binding to props.

Change from this

as={<FormDatePicker />}

to

as={FormDatePicker()}
keikai
  • 14,085
  • 9
  • 49
  • 68
  • Just one question. Why is it that my component needs to be declared as function, where as the DatePicker are added as a tag? Is it because I implemented mine as an arrow function, and react-datepicker implemented it as a class? – Thomas Segato Apr 02 '20 at 15:03
  • @ThomasSegato Nope, not related to classical or functional, you used the `= props => {`, there is a param there as well as the props `as` doesn't have any passed value. It may differ from other APIs like `onChange` which has an `event`. So for this situation, if you write like `=> {` you can use the `as={}` or `as={FormDataPicker}` as normal – keikai Apr 02 '20 at 15:05