Creating a List programatically in material-ui can be easily achieved by following these steps

I am attempting to create a contact view using the list component from Material-UI. My code is written in typescript, but I am struggling with setting up react and material-ui correctly. Any guidance would be greatly appreciated.

export interface IContact {
    contactName: wx.IObservableProperty<string>;
}

export abstract class Contact implements IContact {
    contactName: wx.IObservableProperty<string>;

    constructor() {
        this.contactName = wx.property<string>();
    }
}

/// <reference path="icontact.ts" />

import {IContact, Contact} from '../models/icontact.ts'

export interface IPersonContact extends IContact {
}

export class PersonContact extends Contact implements IPersonContact {
    constructor() {
        super();
    }
}

/// <reference path="../../../typings/tsd.d.ts" />
/// <reference path="../models/icontact.ts" />
/// <reference path="../models/personcontact.ts" />

'use strict';

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as Mui from 'material-ui';
import {IContact} from '../models/icontact.ts'
import * as MuiStyles from 'material-ui/lib/styles';
import {IPersonContact, PersonContact} from '../models/personcontact.ts'

interface ContactViewPros {
}

interface ContactViewState {
}

class ContactView extends React.Component<ContactViewPros, any>{

    itemAddedSubscriber: Rx.IDisposable;
    itemRemovedSubscriber: Rx.IDisposable;

    dataSource: wx.IObservableList<IContact>;
    items: Array<Mui.ListItem>;

    constructor() {       
        super();
        this.state = { muiThem: MuiStyles.ThemeManager.getMuiTheme(MuiStyles.LightRawTheme) };

        this.dataSource = wx.list<IContact>();

        this.itemAddedSubscriber = this.dataSource.itemsAdded.subscribe(changedInfos => this.onContactsAdded(changedInfos));
        this.itemRemovedSubscriber = this.dataSource.itemsRemoved.subscribe(changedInfos => this.onContactRemoved(changedInfos));

        let contact = new PersonContact();
        contact.contactName('adam');
        this.dataSource.add(contact);
    }    

    onContactsAdded(changedInfos: wx.IListChangeInfo<IContact>): void {
        changedInfos.items.forEach(contact => {
            console.log("Contact-list changed");
        });
    }

    onContactRemoved(changedInfos: wx.IListChangeInfo<IContact>): void {
    }

    getInitialState() {
        return this.state;
    }

    componentWillUnmount() {
        this.itemAddedSubscriber.dispose();
        this.itemRemovedSubscriber.dispose();
    }

    renderContactList() {
        this.items = this.dataSource.map<Mui.ListItem>(contact=> {
            var listItem = new Mui.ListItem();
            listItem.props = {
                initiallyOpen: true
            };
            return listItem;
        });
    }

    render() {
        var items = this.renderContactList();
        return <Mui.List>{items}</Mui.List>;
    }
}

export default ContactView;

Answer №1

If you're looking to build components in React without using JSX syntax, you can achieve this by calling the React.createElement method with the necessary arguments: React.createElement(Component, { props }, children).

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

Encountering npm3 installation errors with typyings in Angular 2?

Each time I try to sudo npm install Angular 2 modules, everything updates and installs correctly. However, I encounter the following error when the typings install is attempted: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0 ...

Issue encountered when attempting to assign a local variable as the initial value of an enum object member

Check out this playground link for a TypeScript example. I'm having issues setting the initial value of an enum member using a constant numeric value. Unfortunately, all subsequent values give an error stating "Enum member must have initializer." Is ...

What is the best way to export a React Material-UI component with two separate styles objects in Material-UI V1?

We are currently utilizing material-ui version 1 and composing Higher Order Components (HOC) with the recompose utility. Our issue arises from having two separate styles objects - one defined within the component itself, and another general style object th ...

Using Sanitize.css to customize Material UI styles

Currently, I am utilizing Next JS (v9.2) along with Material-UI (4.9.0). In my code in the _app.js file, I have imported sanitize.css (v11.0.0). However, I have noticed that when implementing a material-UI outlined text-field, the outline does not appear ...

Detecting clicks outside of a component and updating its state using Typescript in SolidJS

Hi there, I am currently learning the SolidJS framework and encountering an issue. I am trying to change the state of an element using directives, but for some reason it is not working. Can anyone point out what I might be doing wrong? You can find the ful ...

Caution: Unable to load bindings, resorting to pure JS instead (consider running npm run rebuild?) within AWS SAM

When I run a sam local invoke to call a typescript AWS Lambda function locally, I am encountering a warning: 2023-04-04T08:53:29.931Z undefined WARN bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?) Should I conf ...

What is the best way to determine the data type of one property in an array of objects based on another property

I have been working on creating a straightforward parser that relies on rules provided by the constructor. Everything seems to be running smoothly, but there are some issues with data types. interface RuleBase { parse(text: string, params: Record<stri ...

Filtering for Material Autocomplete is limited to the getOptionLabel field

Currently, I am utilizing the Google Material-UI autocomplete component. It is currently only filtering based on the "getOptionLabel" option field when text is entered into the input field. However, I would like the autocomplete to filter based on more tha ...

Next.js React Server Components Problem - "ReactServerComponentsIssue"

Currently grappling with an issue while implementing React Server Components in my Next.js project. The specific error message I'm facing is as follows: Failed to compile ./src\app\components\projects\slider.js ReactServerComponent ...

Customizing AxiosRequestConfig with Axios in TypeScript can greatly enhance the functionality and

Currently working with React and Axios. Lately, I've been experimenting with custom configurations in Axios as shown below: import $axios from 'helpers/axiosInstance' $axios.get('/customers', { handlerEnabled: false }) However, wh ...

Unable to retrieve React state within the callback function

As I work with the following components: const ParentComponent: React.FC = () => { // Setting newType to some value within the code const [newType, setNewType] = useState<any>(undefined); // Enabling addEdge to true in another part o ...

What is the best method for emptying a parent's MUI Autocomplete field?

//MAIN PARENT COMPONENT const App = () => { const [filterData, setFilterData] = useState({ //field id and names soldTo:"", soldToName:"", }); const handleChangeAuto = (name, value) => { setFilterData({ ...filterData, ...

Angular Component - Array missing initial value in @Input property

Having trouble transferring values between components? I'm currently dealing with a situation involving two components: report-form and comment-form. The report form contains an array of comments, displaying a list of comments and a button for each on ...

I am unsure of how the rendering logic works for 'checked: {}', but I have observed that it does function properly. If I remove it, the color appears to become lighter

const CustomCheckbox = withStyles({ root: { color: orange[500], '&$checked': { color: orange[700], }, }, checked: {}, })(props => <Checkbox color="default" {...props} />); For more detailed code, check out th ...

What could be causing TypeScript to raise an issue when a /// reference comes after the 'use strict' statement?

This particular inquiry is somewhat connected to a question I posted on Stack Overflow yesterday about why TypeScript is encountering issues when trying to import a module. The initial configuration remains unchanged. My TypeScript file appears as follows ...

styled components are having issues with background gradients and opacity not functioning properly

Hello, I am currently working with styled components and have the following global style code: const GlobalStyle = createGlobalStyle` html{ font-family: roboto; background: linear-gradient(45deg,rgba(137,255,255,0.5),rgba(161,252,143, 0 ...

Combining ReactJS event handling for onClick and onKeyDown into a single handler for TypeScript

To ensure accessibility compliance, I am incorporating onKeyPress handlers into my application. However, I am facing a challenge with interactive <div /> elements. Here are the event handlers I want to trigger on click: const handleViewInfoClick = ( ...

establishing the default value as p-multiselect

Here is the code snippet I am currently working on: export class LkBoardStatus { id : number = 0; descr : string = ''; } In the component.ts file, I have defined the following: //... lkBoardStatusList: LkBoardStatus[] = []; selectedStat ...

You cannot use .addCursorFlag() with Mongoose Typescript

Here is my mongoose model that retrieves data from the database using a cursor. The cursor has a timeout of 10 minutes as per the documentation. const cursor = this.importRecordModel.find().cursor() I attempted to add the following code at the end of the ...

Extract data from a string and assign it to a variable representing an

I have a custom function that parses a string and converts numbers and boolean values to their appropriate JavaScript primitives. This function is specifically designed for working with query parameters: const parseQueryParams = (searchString: string) => ...