Возможно, это действительно простое решение, но я ищу способ отправить функцию обратного вызова в конструктор класса и использовать эту функцию обратного вызова для обновления состояния в исходном классе (в реакции-родной кстати).
Вот что у меня так далеко:
export class A extends Component {
constructor(props) {
super(props);
this.state = {
bluetooth: {
isConnected: "false",
preventAutoReconnect: false,
connected: {
id: "",
name: "none",
obj: {}
}
}
};
this.b = new Bluetooth(this.updateBleContext);
}
updateBleContext = bleInfo => {
console.log("updating context");
this.setState({
bluetooth: bleInfo
});
};
}
Попытка использовать вот так:
export default class B {
constructor(updateContext) {
this.bluetooth = {
isConnected: "false",
preventAutoReconnect: false,
connected: {
id: "",
name: "none",
obj: {}
}
};
this.updateContext = updateContext();
}
setDisconnected = () => {
let bluetooth = this.bluetooth;
bluetooth.connected.name = "";
bluetooth.connected.obj = {};
bluetooth.isConnected = "false";
this.updateContext(bluetooth);
this.bluetooth = bluetooth;
};
}
любая помощь значительнооценили!