onPress syntex confusing


i am confused in onPress syntex. first call using = and {} but second is using :

can anyone explain ?

What you’re seeing in this example are two completely different syntaxes mixed together. Each has its own way of assigning a value.

The first syntax is markdown. Button is a markdown element, and title, color, and onPress are attributes of that element. The way to assign a value to an attribute is with =.

The second syntax is JavaScript. Everything in the outer {} is JavaScript, and what we see here is a JavaScript array containing two JavaScript object literals. The way to assign a value in a JavaScript object literal is with :.

1 Like