Fork me on GitHub
#reagent
<
2019-07-04
>
dominicm14:07:46

When using create-class, how can I access this from my custom functions on the class? this-as is giving me window, but the create-react-class docs say that the function should be bound with the correct this automatically.

dominicm14:07:32

Ah, a workaround, create the function in :get-initial-state.

lilactown15:07:37

I think there’s either a reagent.core/this or reagent.core/component function that you might use?

lilactown15:07:41

not sure atm

dominicm16:07:42

there's a current-component function, but it didn't work in that context. I don't know the impl, I'm guessing it looks for a bound this?

lilactown16:07:08

it looks like it does place the methods on the prototype of the class

lilactown16:07:26

it might be the way you’re calling them

lilactown16:07:52

if you’re tearing them off the object and passing them in (e.g. as event handlers):

:doThing (fn []  (this-as this
           (js/console.log this)))
:render (fn [this]
  [:button {:on-click (.-doThing this)} “Click”])

lilactown16:07:24

then it will lose the this context when you pass in the method as the value

tokoma19:07:00

Now, I am thinking of how I import an icon in cljs and reagent code.

import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
<Avatar className={classes.avatar}>
          <LockOutlinedIcon />
        </Avatar>
Another thing is style in Material UI. Mui is using makeStyles for doing this:
import { makeStyles } from '@material-ui/core/styles';
const useStyles = makeStyles(theme => ({
  '@global': {
    body: {
      backgroundColor: theme.palette.common.white,
    }
.....
Please let me know if anyone knows cljs code.

tokoma22:07:54

The original code shows like above and my code does as follows: