0

I was trying to go the simplest way using Object.assign:

import React, { Component } from 'react'
import { StyleSheet, View, Text, Button } from 'react-native'

class MySuperClass {
  firstMethod() {
     console.log("method 1")
  }
}

const a = Object.assign({}, Component, MySuperClass)

  class CategoriesScreen extends a {

    render() {
      return (
        <View>

        </View>
    );
    }
  };

Yet I'm receiving the error :

TypeError: SUper expression must either be null or a function

I researched it but it fits to different cases than this one

How can I extend one object that includes both the MySuperClass and the react Component?

(PLEASE NOTE: I know I can extend Component in MySuperClass as a work around, but I'm interested to know how to achieve it with this approach, thanks)

1 Answer 1

1

You can do

Object.assign(MySuperClass.prototype, Component.prototype);

here is a more complete example: https://codesandbox.io/s/react-component-with-objectassign-c9es0

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

2 Comments

Thanks but I specifically wrote that I'm aware of this solution already

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.