Fork me on GitHub
#clojurescript
<
2022-12-28
>
M J14:12:51

Hello, I am using '@mui/x-date-pickers-pro/DateRangePicker' This is the component I want to use from MUI

import TextField from '@mui/material/TextField';
import Box from '@mui/material/Box';
import { LocalizationProvider } from '@mui/x-date-pickers-pro';
import { AdapterDayjs } from '@mui/x-date-pickers-pro/AdapterDayjs';
import { DateRangePicker } from '@mui/x-date-pickers-pro/DateRangePicker';

export default function BasicDateRangePicker() {
  const [value, setValue] = React.useState([null, null]);

  return (
    <LocalizationProvider
      dateAdapter={AdapterDayjs}
      localeText={{ start: 'Check-in', end: 'Check-out' }}
    >
      <DateRangePicker
        value={value}
        onChange={(newValue) => {
          setValue(newValue);
        }}
        renderInput={(startProps, endProps) => (
          <React.Fragment>
            <TextField {...startProps} />
            <Box sx={{ mx: 2 }}> to </Box>
            <TextField {...endProps} />
          </React.Fragment>
        )}
      />
    </LocalizationProvider>
  );
}
HOW do I convert it in clojure so that I sent the value as an array of 2 nils. Imports are all correct, since when I use date-picker without range it works. Thisis what I have now
(let [date-range (r/atom ["" ""])]
                                 (fn []
                                 [localization-provider {:date-adapter   cljs-time-adapter
                                                       :adapter-locale {:start "Check-in" :end "Check-out"}}
                                [stack
                                 [date-range-picker {:value @date-range
                                                     :onChange (fn [value1 value2]
                                                                 (println value1))
                                                     :render-input (react-component [startProps endProps]
                                                                                    [text-field startProps]
                                                                                    [text-field endProps])}]]]))

p-himik14:12:09

Seems like you're using Reagent so a better suited channel would be #C0620C0C8. You probably have to convert the CLJS vector into a JS array with clj->js.

M J14:12:19

Ok, I will try there. thanks

p-himik14:12:24

There's no need to cross-post when I have already given an answer here.

M J14:12:37

IT didnt work

p-himik14:12:46

Are there any errors in the JS console?

M J14:12:02

"Cannot read properties of undefined (reading '0')"

p-himik14:12:54

Well, there you go. :) Figure out what that undefined is (or rather, was supposed to be), given the stack trace and the debugging capabilities of the browser.

Sam Ritchie17:12:11

You need :> before a vanilla react component

p-himik17:12:49

Given that they say that it works without a value, I assume adapt-react-component was used.

👍 1