Skip to content
Discussions/App Development/[Suggestion / feature request] DamlHubLogin from @daml/hub-react, onClickForum ↗

[Suggestion / feature request] DamlHubLogin from @daml/hub-react, onClick

App Development3 posts188 views1 likesLast activity Apr 2022
RI
rikotacardsOP
Apr 2022

I want to pass onClick callback to my rendered button via the render option, however at the moment I don’t think it’s possible, unless I’m doing something wrong here. The end goal is to toggle a loading state when I click login.

I’m guessing it’s due to this line

github.com

digital-asset/dabl-react/blob/4d15cf66dc506f682513914fe6c8d96cdf903ab7/src/login/DamlHubLogin.tsx#L205

      
        
  1. }
  2. } else {
  3. onLogin && onLogin(new PartyToken(tokenFromCookie));
  4. }
  5. };
  6. if (showButton) {
  7. if (options?.method?.button?.render) {
  8. const comp = options.method.button.render();
  9. return React.cloneElement(comp, {
  10. onClick: handleButtonLogin,
  11. children: [
  12. ...React.Children.toArray(comp.props.children),
  13. <span key="damlhub-login-custom-button-text">{text}</span>,
  14. ],
  15. });
  16. } else {
  17. return (
  18. <a id="log-in-with-hub" onClick={handleButtonLogin}>
  19. {text}
  20. </a>

What I’d like to be able to do is pass in a function that can set a state, eg isLoading, so when I click on the button, I can get some reaction

My component looks like this, and I want to pass an onClick to the LoadingButton componenet.

<DamlHubLoginBtn
        withButton
        withToken
        onLogin={(creds) => {
          console.log("ON LOGIN");
          if (creds) {
            login(creds, admin);
          }
        }}
        options={{
          method: {
            button: {
              text: "Log Into Wallet",
              render: () => (
                <LoadingButton
                  onClick={() => {
                     // I CANT GET IT TO LOG
                    console.log("HI");
                  }}
                  loading={false}
                  loadingPosition="end"
                  sx={{ margin: 1 }}
                  variant="contained"
                  fullWidth
                ></LoadingButton>
              ),
            },
          },
        }}
      />
AL
Alex_Matson
Apr 2022

Hi @rikotacards ,

Thanks for pointing this out! As you discovered, the library does not support custom onClick handlers at this time. I’ll need to think about how to best add support for this in a future release

RI
rikotacards
Apr 2022

Thanks!
and the only work around I can find is just to wrap the damlHubLogin component with a div or button in my app, then I do an onClick from there.
But then if I use withToken, that div wraps around the entire text input as well.

← Back to Discussions