Help setting monday.listen method using the SDK

Hello community,

I am now taking Monday.com API certificate course and very new in code writing.
I have built a board view app with the sentence “Hello, monday apps!”. I need then to set an event listener using the monday.listen method so when a background color is changed, the selected color will actually apear in that board view. Unfortunatelly I get an error massages like “unexpected token” or “Missing Semicolon”.
Here is the code, your help will be appreciated. Thank you :slight_smile:

import React from “react”;
import { useState, useEffect } from “react”;
import “./App.css”;
import mondaySdk from “monday-sdk-js”;
import “monday-ui-react-core/dist/main.css”;
//Explore more Monday React Components here: https://style.monday.com/
import AttentionBox from “monday-ui-react-core/dist/AttentionBox.js”;

// Usage of mondaySDK example, for more information visit here: Software development kit (SDK)
const monday = mondaySdk();

const App = () => {
const [context, setContext] = useState();

useEffect(() => {
// Notice this method notifies the monday platform that user gains a first value in an app.
// Read more about it here: monday.execute
monday.execute(“valueCreatedForUser”);

// TODO: set up event listeners, Here`s an example, read more here: https://developer.monday.com/apps/docs/mondaylisten/

componentDidMount() {
monday.listen(“settings”, res => {
this.setState({ settings: res.data });
});
}

//Some example what you can do with context, read more here: monday.get
const attentionBoxText = Hello, your user_id is: ${ context ? context.user.id : "still loading" }. Let's start building your amazing app, which will change the world!;

return (

Hello, monday Apps!
); };

export default App;

1 Like

I’m having the same issue.
The documentation is not too helpful

I think @kranthi_thoughtflow is seeing this too – Issue with monday.listen call

1 Like

Hello there @mmorales,

A fix has been deployed. Would you be able to please try again now?

Nothing changes
I’m pasting the same lines before the
"//Some example what you can do with context " comment

Hi @mmorales,

It looks like the quotes being used there on line 39 are not the correct ones. Not sure if you saw that issue.

@mmorales This should really be a new thread, but I see 2 problems.

  1. As @Matias.Monday says, you need plain quotes like this: "
  2. You’re trying to use componentDidMount in a functional component. That will only work in the older style class based React component. Delete the componentDidMount bit & move the monday.listen("settings"...); bit into the useEffect(()=> {...}).

The single quote at 39 closes the one at 36, since it contains the “still loading” which has double quotes. So there’s is no issue regarding the quotes there.

The problem are not the quotes, specially because when I deleted the componenDidMount part it works.

@mmorales yeah, the problem quotes I see are on line 30 in the componentDidMount :slight_smile:
Glad its working now.