nanojsx / nano

🎯 SSR first, lightweight 1kB JSX library.
http://nanojsx.io
MIT License
1.46k stars 38 forks source link

[Enhancement] Add optional CSS class to Router.Link #65

Closed jrson83 closed 2 years ago

jrson83 commented 2 years ago

Describe Currently it's not possible to add a CSS class like class="nav-link" to Router.Link.

(alias) const Link: FC<{
    to: string;
    replace?: boolean | undefined;
    children?: any;
}>

My current workaround:

<Link to="/about" cssClass="nav-link">About</Link>
export const Link: Nano.FC<{ to: string; cssClass: any; children?: any }> = ({ to, cssClass, children }) => {
  const handleClick = (e: Event) => {
    ...
  }

  return (
    <a href={to} class={cssClass} onClick={(e: Event) => handleClick(e)}>
      {children}
    </a>
  )
}

Have a question? If im not wrong, it would be great if you could add an optional CSS class to the Router.Link.

yandeu commented 2 years ago

Right, I will have to add this.


It is a better workaround to use to():

import { to } from 'nano-jsx/lib/components/router'

<div>
  <style>{'.my-class { color:blue; }'}</style>
  <a href="/somewhere" class="my-class" onClick={() => to('/somewhere')}>
    Somewhere
  </a>
</div>