Skip to content

Can I use an external react component inside Docusaurus? #806

Closed

Description

@caiorasc

Is this a bug report?

No, this is a doubt

Have you read the Contributing Guidelines on issues?

Yes

Environment

yarn outdated v1.5.1, Windows 10, node v8.9.3

Steps to Reproduce

I'm trying to use redoc as a react component, inside Docusaurus, but doesn't work

(Write your steps here:)

  1. Follow the Docusaurus Getting Started tutorial
  2. Go to website directory and install redoc yarn add redoc
  3. Inside pages directory, create a new file called docApi.js and put the code below:
const React = require('react');
import { RedocStandalone } from 'redoc';

class docApi extends React.Component {
    render() {
        return (
            <div>
                <RedocStandalone
                    specUrl="https://rebilly.github.io/ReDoc/openapi.yaml"
                    options={{
                        nativeScrollbars: true,
                        theme: { colors: { main: '#dd5522' } },
                    }}
                />
            </div>
        );
    }
}

module.exports = docApi;
  1. Run the local webserver via yarn start and put /docApi.html on the url to see the error

Expected Behavior

I expect something like site rebilly redoc

Actual Behavior

I only see the static svg loading

Reproducible Demo

Reproducible Demo Repo

Activity

  1. endiliey commented on Jun 30, 2018

    @endiliey
    Contributor

    Sorry for the late response. Unfortunately, the answer is no atm. We are addressing this in v2 😊

  2. endiliey commented on Oct 23, 2018

    @endiliey
    Contributor

    Yes. But only in v2.

    Coming soon

  3. franc0is commented on Nov 19, 2019

    @franc0is

    For what it's worth, I just tried this in V2 and it works :-).

  4. caiorasc commented on Nov 19, 2019

    @caiorasc
    Author

    Thanks, I'll try the v2

  5. chase2981 commented on Nov 29, 2020

    @chase2981

    Could someone please tell me how to accomplish something like the following please? Essentially I can't have all my docs and my components be in the same directory cuz i have multiple apps in my project. Therefore I have a flex-docs folder, (which is essentially the docusaurus "website" folder) then I have a flex-plugins folder, a flex-webchat-ui folder, and aflex-lib folder. My problem is everything works all fine and dandy until I try to use any third party libs in the component that my mdx file is referencing. (See https://codesandbox.io/s/sharp-austin-m0z74?from-embed=&file=/flex-docs/docs/doc2.mdx for more details which mirrors my real setup) So it works in my real setup if the Test component is just plain with no imports, but as soon as I import any styled-components into the Test component, or any @material-ui/core components into my Test component, then all the sudden it starts throwing the following error. I don't get it. I made sure the react versions were the same and everything. I'm using docusaurus v2. (https://codesandbox.io/s/sharp-austin-m0z74?from-embed=&file=/flex-plugins/src/components/demo.jsx)

    Any help would be greatly appreciated! I love your product.

    P.s. I found this thread by searching "docusaurus invoke component in another directory" btw.. Thnx in advance!

    Screen Shot 2020-11-28 at 11 18 01 PM

  6. slorber commented on Nov 30, 2020

    @slorber
    Collaborator

    @chase2981 what you are looking for is likely a Yarn Workspace / Lerna monorepo. That's not really related to this issue not Docusaurus but is related to modularisation of your own js code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions