#Export from `.client` file?

1 messages · Page 1 of 1 (latest)

pearl crane
#

I'm trying to export from a .client file but I'm getting an empty object. If I remove the .client extension, it works... but once the server is restarted, I get an error about window not being defined. Is there a way to do this?

ruby marsh
#

any .client file will give you an empty object as export on the server

#

you need to check client-side only

pearl crane
#

You mean the remix-utils thing?

ruby marsh
#
// app/something.client.ts
export function sum(a: number, b: number) {
  return a + b
}

// app/routes/_index.tsx
import { sum } from "~/something.client"

export default function Component() {
  useEffect(() => {
    console.log(sum(1, 2))
  })

  return null
}
ruby marsh
#

if you're exporting just a function you can use it in an effect or event listener

#

if you're exporting a React component you need to wrap it in ClientOnly

pearl crane
pearl crane
#

...I'll give that a shot.

#

...that didn't work. window is undefined in the machine file now.

ruby marsh
#

the problem is you need to ensure the file only runs client-side, the extension avoids shipping the code to the server, but if you try to call it server-side it will fail

pearl crane
# ruby marsh the problem is you need to ensure the file only runs client-side, the extension ...

I was just reading this:

The only issue is ClientOnly breaks in v2..
Is that true?
https://stackoverflow.com/questions/74910021/adding-a-client-suffix-to-my-jsx-or-tsx-file-breaks-the-import-in-remix

ruby marsh
#

it works perfectly fine

pearl crane
#

I just want to use Remix 1.6 for the rest of my life. That was awesome. Nothing works anymore.

pearl crane
#

Thanks..

ruby marsh
ruby marsh
pearl crane
# ruby marsh I think the issues this person mentions is probably because the v7 of remix-util...

I'm having issues with the new routing system also. I tried using this but I started getting errors, so I gave up on it.
https://www.npmjs.com/package/@remix-run/v1-route-convention
What was the last version of Remix that used the old routing system? You say, I can still use that?

ruby marsh
#

I use 1.19.3

#

that's the latest v1 release

pearl crane
#

?

ruby marsh
#

there's no later version of v1

#

after 1.19.3 the next release was 2.0.0

pearl crane
#

That's what I mean. Doesn't 1.19.3 use the new system

#

?

ruby marsh
#

by default it comes with the v2 convention enabled, but you can disable it in the remix.config.js

pearl crane
#

Oh

ruby marsh
#

just set v2_routeConvention: false

pearl crane
#

Didn't know that.

#

Jesee Louise.

ruby marsh
#

every future flag is enabled by default but you can disable them