question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to pass 'onRemove' on custom made Tokens (withToken/useToken)

See original GitHub issue

Is your feature request related to a problem? Please describe. I created a custom Token using useToken on my functional component. I have no idea how to pass the onRemove function since my custom token is rendered like this (within the render() of my main component):

{this.state.selected.map((option, idx) => (
  <CustomToken
    key={idx}
    option={option}
    logo={option.logo}
    name={option.name}
  ></CustomToken>
))}

This is the CustomToken component:

const CustomToken = (props) => {
  return (
    <div
      {...useToken(props)}
      className="row w-50"
      option={props.option}
      onRemove={props.onRemove}
      >
      <div className="col">
        <img src={props.logo} style={{ width: 2 + "rem" }} />
      </div>
      <div className="col">{props.name}</div>
    </div>
  );
};

Of course I get Warning: Unknown event handler property onRemove. It will be ignored. By the way, in order to have my tokens rendered somewhere else (instead of in the input field), I’m using renderInput to decouple the two as seen here. This is my renderInput function:

renderInput = ({ inputRef, referenceElementRef, ...inputProps }) => {
  delete inputProps.inputClassName; //removes the not used inputClassName property
  return (
    <div>
      <input
        {...inputProps}
        className="form-control"
        ref={(input) => {
          inputRef(input);
          referenceElementRef(input);
        }}
        type="text"
      />
    </div>
  );
};

Describe the solution you’d like Since I’m positioning my CustomToken in a different place than inside the input bar, I would like to pass the onRemove function to a custom token.

How is this solution useful to others? This feature would allow for truly customizable Tokens.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alexferrari88commented, Aug 6, 2020

You are the best!! Thank you so much, it works!!

0reactions
ericgiocommented, Aug 6, 2020

@alexferrari88: Now you’re not applying useToken at all. You had the right idea before, you just weren’t handling the props correctly. If you look at the result of useToken, you’ll see it returns a bunch of props. Those need to be properly applied in your CustomToken:

const CustomToken = (props) => {
  const { active, onRemove, option, ...rest } = useToken(props);

  return (
    <div className="w-50" {...rest}>
      <img src={option.logo} style={{ width: 2 + "rem" }} />
      {props.children}
      <ClearButton
         className="rbt-token-remove-button"
         label="Remove"
         onClick={onRemove}
         tabIndex={-1}
       />
    </div>
  );
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Create Custom Tokens | Firebase Authentication - Google
You generate these tokens on your server, pass them back to a client device, and then use them to authenticate via the signInWithCustomToken()...
Read more >
Customize tokens returned from Okta with a dynamic allow ...
This guide explains how to define custom Group claims for tokens that are returned from Okta, by using a dynamic allowlist to define...
Read more >
How to Add Your Custom Tokens in MetaMask
Looking for a specific ERC-20 token? Here's how to add your custom tokens and turn on the auto-detection feature.
Read more >
Adding Custom Claims to ID Tokens with Auth0 Actions
Learn how to create a new custom Action that will add a custom claim to your Auth0-issued ID Token.
Read more >
How do I add a custom token? - Exodus Support
To add a custom token, open the Web3 Wallet and a) click the Profile icon, then b) click Assets. 2. Next, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found