Reputation: 445
i have a modal form dialog to enter name (data) and when the button submit clicked i wanted it to display alert message for example: '(data) have been added to the list!' sorry if this is too dumb, i am still new to reactjs thank you
this is currently my code
handleCreate = () => {
const form = this.form;
form.validateFields((err, values) => {
if (err) {
return;
}
var data = this.state.data
values.data = []
data.push(values)
this.setState({ data:data });
console.log(data)
this.setState({ visible: false });
form.resetFields();
alert('{data} have been added!');
});
Upvotes: 4
Views: 18595
Reputation: 21191
It looks like you are trying to use Template literals, so you need to use backticks (`
) instead of single ('
) or double ("
) quotes. Also, placeholders are preceded by a dollar sign: ${expression}
.
Lastly, if the data you are trying to display is an object, you will always see [Object object]
unless you use JSON.stringify()
.
const debugMessage = "This data has been added";
const debugData = { foo: 1, bar: 2 };
alert(`${ debugMessage }: ${ debugData }`);
alert(`${ debugMessage }: ${ JSON.stringify(debugData, null, ' ') }`);
Upvotes: 0
Reputation: 946
alert(this.state.data + 'have been added!');
this is the solution, hoping i have not understood your question wrongly
Upvotes: 6