0

So I am trying to use react-mde as seen here https://github.com/andrerpena/react-mde

But I am getting the error "undefined is not a function" in my setup for some reason and I cannot figure out why.


import * as React from "react";
import ReactMde from "react-mde";
import ReactDOM from "react-dom";
import * as Showdown from "showdown";
import "react-mde/lib/styles/css/react-mde-all.css";

const converter = new Showdown.Converter({
  tables: true,
  simplifiedAutoLink: true,
  strikethrough: true,
  tasklists: true,
});

function NormEdit() {
  const [value, setValue] = React.useState("**Hello world!!!**");
  const [selectedTab, setSelectedTab] =
    (React.useState < "write") | ("preview" > "write");
  return (
    <div className="container">
      <ReactMde
        value={value}
        onChange={setValue}
        selectedTab={selectedTab}
        onTabChange={setSelectedTab}
        generateMarkdownPreview={(markdown) =>
          Promise.resolve(converter.makeHtml(markdown))
        }
      />
    </div>
  );
}

export default NormEdit;


this is my code, and below is the line that the error is occuring on


const [selectedTab, setSelectedTab] =
    (React.useState < "write") | ("preview" > "write");

any help would be much appreciated =]

1 Answer 1

1

Your selectedTab useState needs to be something more like this:

const [selectedTab, setSelectedTab] = React.useState<"write" | "preview">("write");

This part <"write" | "preview"> looks like typescript and means that the selectedTab state is only ever allowed to be a string that's either "write" or "preview".

Sign up to request clarification or add additional context in comments.

4 Comments

This will only work with typescript so I get an error
Take out the typing then and have it be React.useState("write").
const [selectedTab, setSelectedTab] = React.useState("write"); seemed to solve it as you suggested, removing the other parts should not effect the rest of the code right?
Nope, if you aren't using TypeScript it should be just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.