Reputation: 3592
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)
Upvotes: 0
Views: 26
Reputation: 724
You can do
Object.assign(MySuperClass.prototype, Component.prototype);
here is a more complete example: https://codesandbox.io/s/react-component-with-objectassign-c9es0
Upvotes: 1