mondaycom / welcome-apps

A collection of "Hello World" monday.com apps
https://developers.monday.com
MIT License
85 stars 140 forks source link

Quickstart react #82

Open mminin opened 1 year ago

mminin commented 1 year ago

The tutorial does not explain how the colour button in Customise View supposed to change the background colour. Using colour picker has no effect. Probably because a hook for it is missing in App.js? It seems to be necessary to add the following line under const App:

const [background_color, setSettingsBG] = useState('red');

And then a handler under useEffect()

monday.listen("settings", (res_set) => {
      setSettingsBG(res_set.data.background_color);
    });

and finally assign a style to the div:

const mystyle = {
    backgroundColor: background_color
  };
  console.log(background_color);

  return (
    <div className="App"
        style={mystyle}
          >
      <AttentionBox
        title="Hello Monday Appssss!"
        text={attentionBoxText}
        type="success"
      />
    </div>
pslootweg commented 1 year ago

More than that, you will need to persist the setting for your own App and load them at the start of the App execution, otherwise each invocation of the app will start with undefined settings.