I'm trying to style my react-dates
DayPickerRangeController
in Typescript, using react-with-styles and Aphrodite. I'm using this code, emulating the code from https://github.com/airbnb/react-dates#interfaces:
const ThemedStyleSheet = require('react-with-styles/lib/ThemedStyleSheet').default
const aphroditeInterface = require('react-with-styles-interface-aphrodite').default
const DefaultTheme = require('react-dates/lib/theme/DefaultTheme').default
ThemedStyleSheet.registerInterface(aphroditeInterface)
ThemedStyleSheet.registerTheme(DefaultTheme)
// Importing react-dates after registering the theme, as per the docs.
import * as ReactDates from 'react-dates'
However, when I run this I get this runtime error in console:
Cannot read property 'createLTR' of undefined
TypeError: Cannot read property 'createLTR' of undefined
at Object.createLTR (http://localhost:6006/static/preview.bundle.js:133281:47)
at createStyles (http://localhost:6006/static/preview.bundle.js:9710:59)
at WithStyles.maybeCreateStyles (http://localhost:6006/static/preview.bundle.js:9805:22)
at WithStyles.componentWillMount (http://localhost:6006/static/preview.bundle.js:9739:20)
at callComponentWillMount (http://localhost:6006/static/preview.bundle.js:42214:16)
at mountClassInstance (http://localhost:6006/static/preview.bundle.js:42310:7)
at updateClassComponent (http://localhost:6006/static/preview.bundle.js:43679:9)
at beginWork (http://localhost:6006/static/preview.bundle.js:44320:16)
at performUnitOfWork (http://localhost:6006/static/preview.bundle.js:47152:16)
at workLoop (http://localhost:6006/static/preview.bundle.js:47181:26)
I do not get this error when:
I use the
registerInterfaceWithDefaultTheme
function from the class (this doesn't allow me to style the component, though). (This surprises me because the code inregisterInterfaceWithDefaultTheme
looks the same as what I have (to me at least))const aphroditeInterface = require('react-with-styles-interface-aphrodite').default const registerInterfaceWithDefaultTheme = require('react-dates/lib/utils/registerInterfaceWithDefaultTheme') .default registerInterfaceWithDefaultTheme(aphroditeInterface)
I use
import 'react-dates/initialize';
(which eventually callsregisterInterfaceWithDefaultTheme
).
I still get this error when:
- I swap the order of registering the theme and the interface
- I add the
ThemedStyleSheet
code at the top of mysrc/index
file, as opposed to in the same file as the one that usesDayPickerRangeController
(This is the suggested fix in https://stackoverflow.com/a/48558841/1176156) - I put the exact code from https://github.com/airbnb/react-dates#interfaces in Javascript, then import that into my Typescript file that's using
DayPickerRangeController
.
I have confirmed in the debugger that all of my imports are getting valid code, and not e.g. undefined
.