Skip to content

Missing Undefined check in React.useState() #77

@ukntpm

Description

@ukntpm

Problem

Currently, there is missing undefined check in React.useState().
Check here :

react-view/src/ast.ts

Lines 228 to 231 in fed53e0

if (
valueNode.type === 'StringLiteral' ||
valueNode.type === 'BooleanLiteral'
) {

Since we are not passing any argument in React.useState(), it's not rendering appropriate content.

Example Code

const [initialCode, setInitialCode] = React.useState("");
const {compilerProps, errorProps, editorProps} = useView({
    initialCode
  });

React.useEffect(() => {
setInitialCode(`() => {
      const [content, setContent] = React.useState(); // not passing any argument
      const text: string = "Hey";
      return <h2>{text}</h2>;
    }`)
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions