Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-2126

Export a default Realm context from `@realm/react`

      Problem

      It's annoying for users to have to create a Realm context (calling createRealmContext) before accessing the useRealm, useQuery and useObject hooks:

      Unable to find source-code formatter for language: tsx. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      import { createRealmContext } from "@realm/react";
      const { RealmProvider, useRealm } = createRealmContext();
      // use the useRealm hook
      

      Solution

      Instead we should create a default Realm context and export its members as named exports, making the average use of the library much simpler:

      Unable to find source-code formatter for language: tsx. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      import { RealmProvider, useRealm } from "@realm/react";
      // use the useRealm hook
      

      We should make sure to document the advanced use-case of working with multiple Realm's (calling createRealmContext) too.

      Alternatives

      No response

      How important is this improvement for you?

      I would like to have it but have a workaround

      Feature would mainly be used with

      Atlas Device Sync

            Assignee:
            andrew.meyer@mongodb.com Andrew Meyer
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: