SocialGouv / e2esdk

SDK to build end-to-end encrypted web applications
https://socialgouv.github.io/e2esdk
Apache License 2.0
20 stars 0 forks source link

feat(react): provide devtools component #61

Open revolunet opened 1 year ago

revolunet commented 1 year ago

Can we provide a full DevTools react component so we dont have to add this to each project ?

import '@e2esdk/devtools'
import { E2ESDKDevtoolsElement } from '@e2esdk/devtools'
import { useE2ESDKClient } from '@e2esdk/react'
import React from 'react'

export const Devtools = () => {
  const client = useE2ESDKClient()
  const ref = React.useRef<E2ESDKDevtoolsElement>(null)
  React.useEffect(() => {
    if (!ref.current) {
      return
    }
    ref.current.client = client
  }, [client])
  return <e2esdk-devtools ref={ref} theme="dark" />
}
franky47 commented 1 year ago

We could, though this would require an additional library, or some sort of circular dependency between the @socialgouv/e2esdk-react and @socialgouv/e2esdk-devtools packages.

The devtools package already has the e2esdk-react package as a dep (should actually be a devDep), so it could be added there. I'll have to check whether the original idea of having the devtools framework-agnostic still stands (ie: not adding react et al to the deps list).

One caveat though with Next.js is that this component will still have to be dynamically imported on client components only (as WebComponents can't be used in SSR, AFAIK).