Skip to content

Mixins use problem with React #6147

Closed
Closed
@xmehaut

Description

@xmehaut

Hello,

I'm trying to use mixins with React. The compiler tells me that I try to reefined as property some features which are functions... Here is the code :

    import * as React from "react"
import * as ReactDom from "react"
import {ClassGenerator} from "../mixins/classgenerator"
import {applyMixins} from "../mixins/mixins"



export  class Component<C,S> extends React.Component<C,S> implements ClassGenerator  {
    constructor(props) {
        super(props); 
    }

    //mixins generic
    setState : (any) =>any  //PB
    forceUpdate : ()=>void      //PB
    render : () =>any              //PB
    props : any
    state:any
    context:any
    refs:  any
    key: any

    //mixin classgenerator
    getClassName : (string, any) => string 
}

with classGenerator

interface Props extends React.Props<ClassGenerator>{
     className: string;
}

export class ClassGenerator extends React.Component<Props, {}>{

    getClassName(defaultClassName, addClassName) : string {
        let classResult = defaultClassName;

        if (typeof this.props.className !== 'undefined') { 
            classResult += ' ' + this.props.className;
        }

        if (typeof addClassName !== 'undefined') {
            if (typeof addClassName === 'object') {
                classResult += ' ' + classNames(addClassName);
            } else {
                classResult += ' ' + addClassName;
            }
        }

        return classResult;
    }
};

any clue?

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