The parameter type 'IScriptEditorProps' does not accept arguments of type 'string'

After trying numerous solutions, I decided to integrate this script editor into a SharePoint site. However, when attempting to implement it, I encountered an issue with the constructor lacking arguments. Despite my efforts to troubleshoot, I have been unable to identify the cause of this problem.

import * as React from "react";
import styles from "./ScriptEditor.module.scss";
import { IScriptEditorProps } from "./IScriptEditorProps";
import {
  Dialog,
  DialogType,
  DialogFooter
} from "office-ui-fabric-react/lib/Dialog";
import {
  DefaultButton,
  PrimaryButton
} from "office-ui-fabric-react/lib/Button";
import { TextField } from "office-ui-fabric-react/lib/TextField";
import { loadStyles } from "@microsoft/load-themed-styles";
require("./overrides.css");
export default class ScriptEditor extends 
React.Component<IScriptEditorProps,any> {

constructor(script: string, title: string) {
  super(script, title);

  this._showDialog = this._showDialog.bind(this);
  this._closeDialog = this._closeDialog.bind(this);
  this._cancelDialog = this._cancelDialog.bind(this);
  this._onScriptEditorTextChanged = this._onScriptEditorTextChanged.bind(
    this
  );

  const uiFabricCSS: string = `
  .pzl-bgColor-themeDark, .pzl-bgColor-themeDark--hover:hover {
    background-color: "[theme:themeDark, default:#005a9e]";
  }
  `;
  loadStyles(uiFabricCSS);
  this.state = {
    showDialog: false
  };
}

public componentDidMount(): void {
  this.setState({ script: this.props.script, loaded: this.props.script });
}
private _showDialog() {
  this.setState({ showDialog: true });
}

private _closeDialog() {
  this.setState({ showDialog: false });
  this.props.save(this.state.script);
}

private _cancelDialog() {
  this.props.save(this.state.loaded);
  this.setState({ showDialog: false, script: this.state.loaded });
}

private _onScriptEditorTextChanged(text: string) {
  this.setState({ script: text });
}

public render(): React.ReactElement<IScriptEditorProps> {
  const viewMode = (
    <span dangerouslySetInnerHTML={{ __html: this.state.script }}></span>
  );

  return (
    <div>
      <div className={styles.scriptEditor}>
        <div className={styles.container}>
          <div
            className={`ms-Grid-row pzl-bgColor-themeDark ms-fontColor-white ${styles.row}`}
          >
            <div className="ms-Grid-col ms-lg10 ms-xl8 ms-xlPush2 ms-lgPush1">
              <span className="ms-font-xl ms-fontColor-white">
                {this.props.title}
              </span>
              <p className="ms-font-l ms-fontColor-white"></p>
              <DefaultButton
                description="Opens the snippet dialog"
                onClick={this._showDialog}
              >
                Edit snippet
              </DefaultButton>
            </div>
          </div>
        </div>
      </div>
      <Dialog
        isOpen={this.state.showDialog}
        type={DialogType.normal}
        onDismiss={this._closeDialog}
        title="Embed"
        subText="Paste your script, markup or embed code below. Note that scripts will only run in view mode."
        isBlocking={true}
        className={"ScriptPart"}
      >
        <TextField
          multiline
          rows={15}
          onChange={this._onScriptEditorTextChanged.bind(this)}
          value={this.state.script}
        />
          <DialogFooter>
          <PrimaryButton onClick={this._closeDialog}>Save</PrimaryButton>
        <DefaultButton onClick={this._cancelDialog}>Cancel</DefaultButton>
      </DialogFooter>
      {viewMode}
    </Dialog>
  </div>
);
}
}

The parameters expected by the constructor and super method are imported from IScriptEditorProps

export interface IScriptEditorProps {
  script: string;
  title: string;
  save(script: string): void;
}

What specific arguments do I need to provide to the constructor and super method?

Answer №1

To utilize props in a React component, simply include them in the constructor and pass them to super. Afterwards, you can access the props values throughout your component by using this.props, such as this.props.script.

constructor(props) {
  super(props);

  ...
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A novel way to enhance a class: a decorator that incorporates the “identify” class method, enabling the retrieval

I have been given the task to implement a class decorator that adds an "identify" class method. This method should return the class name along with the information passed in the decorator. Let me provide you with an example: typescript @identity(' ...

Display or conceal an icon based on the data in the field

Can someone provide guidance on how to make an icon appear or disappear based on the logic within [ngIf]? The icon should only be displayed if there is information in a specific field. Should I implement this inside ngIF or in my TS file? Can the icon cl ...

What are the distinctions in type-narrowing when assigning values using ternary expressions versus if-else statements?

It seems that the type checker is handling the typing of m in print() differently based on whether m was assigned through a ternary expression or an if-else statement. What sets apart the first line in the print() function from the commented code below it? ...

Determining the quantity of variations within a union in Typescript

Is it possible to determine the number of types in a union type in Typescript, prior to runtime? Consider the following scenario: type unionOfThree = 'a' | 'b' | 'c'; const numberOfTypes = NumberOfTypes<unionOfThree>; c ...

Creating a dynamic union return type in Typescript based on input parameters

Here is a function that I've been working on: function findFirstValid(...values: any) { for (let value of values) { if (!!value) { return value; } } return undefined; } This function aims to retrieve the first ...

Utilizing Functions in Next.js with TypeScript: A Guide to Reusability

It is considered a best practice to separate data fetching functions into a folder named services, but I'm having trouble implementing this in my Next.js project. The function works when placed inside the component where I want to render the data, but ...

Typescript validation for redundant property checks

Why am I encountering an error under the 'name' interface with an excess property when using an object literal? There is no error in the case of a class, why is this happening? export interface Analyzer { run(matches: MatchData[]): string; } ...

Previous states in TypeScript

Just starting out with typescript and trying to work with user files in order to update the state. Currently facing a typescript error that I can't seem to figure out - Error message: Argument of type '(prev: never[]) => any[]' is not as ...

Exploring Angular 7: Leveraging class inheritance and the powerful httpClient

It has come to my attention that my services are quite repetitive. In an attempt to enhance them, I decided to delve into super classes and inheritance in Angular. However, I have been struggling with the constructor and super calls. Despite TypeScript com ...

Tips for activating automatic building of packages when utilizing pnpm install?

Our unique project is utilizing a combination of pnpm, workspace, and typescript in adherence to the monorepo standard. Upon cloning the repository, we execute a pnpm install command to download dependencies and establish links between local packages. De ...

What could be the reason for my button not activating my JavaScript function?

I am encountering an issue with my form-validation sample. When I click the submit button, it should display an alert message but it is not working as expected. Here is a link to my sample: sample link I would greatly appreciate any assistance in res ...

Identifying and Blocking Users from Accessing External Domains Outside of the Angular Application

I am working on an angular application and I need to implement a feature where I can detect when a user navigates outside of the app domain from a specific component. For instance, let's say the user is on the upload component processing important in ...

Tips for implementing filters in Angular2 without using the package field in the console

I am currently experiencing an issue with a filter field in my code. The filter works fine when all the package data is present, however, some items do not have a package field. As a result, I need to filter based on the package name but I am encountering ...

Applying the `lean` method to Mongoose queries that retrieve arrays in TypeScript

When working with two Mongoose queries, I made the decision to utilize the .lean() method on both of them. It appears that using .lean() on a query that returns a single document works well: let something:Something; SomethingDocument.findOne({_id:theId}) ...

Using both Typescript and Javascript, half of the Angular2 application is built

My current project is a large JavaScript application with the majority of code written in vanilla JavaScript for a specific platform at my workplace. I am looking to convert this into a web application that can be accessed through a browser. I believe thi ...

What exactly does Type refer to in Angular 2?

I keep encountering the Type keyword in various parts of the documentation. For instance, in this link, it mentions that the ComponentRef has a property called componentType which is of type Type<any>. Upon further investigation, I stumbled upon this ...

Unable to retrieve HTTP call response during debugging, although it is visible in the browser

When I send an HTTP request to create a record, I am able to see the added record id in the Network section of browsers like Chrome and Firefox. However, when I try to debug the code and retrieve the same id value, I encounter difficulties. I have tried us ...

Issues have been encountered with Angular 5 when trying to make required form fields work properly

Just created my first Angular app using Angular 5! Currently following the documentation at: https://angular.io/guide/form-validation. Below is the form I have set up: <form class="form-container"> <mat-form-field> <input matInput pl ...

The Angular 2 router is not compatible with using the same component but with different IDs

Currently utilizing the alpha8 router with 3 main routes: export const appRoutes: RouterConfig = [ { path: '', component: LandingComponent }, { path: 'blog', component: BlogComponent }, { path: 'posts/:id', compon ...

Issue with detecting undefined in a nested function using Typescript

Examining the code snippet provided below, focus on the test getter. Why is it that const name = this.person.name does not result in an error, while const processPerson = () => this.person.name does generate an error? interface Person { name: string; ...