I want to develop a React App with TypeScript, which can store and send MQTT data.
There are a lot of (hundreds) MQTT messages like:
config.laser.enable == "true", config.system.value == "23" or config.user.password == "foobar".
So I end up with an object like:
{
"config.laser.enable": true,
"config.system.value": 23,
"config.user.password": "foobar",
...
}
Each of my visual components will use only a small subset of these topics.
My first approach was to create a MQTT client for each component and subscribe to their individual topics, but this seems to be a lot of overhead. So I believe it would be better to have only one MQTT client, which subscribes to everything and stores the message data in a global state. So my question is: How can I (or shouldn't I?) store complex data (an object) in a global state in React and making sure that only the components redraw when their specific subset of the global state has changed. Can I use React Redux for this?
Can you give me an example on how to do this?
I am new to React, so please forgive if this is trivial.