Hi
I am relatively new to React Native and hence I stumbled upon something by accident.
I was following the React Native Advanced course by Mosh and coding along. I wrote up the following lines which is from Native Features No.10 Building ImageInputList basics.
<View style={styles.container}>
{imageUris.map((uri) => {
<ImageInput
imageUri={uri}
key={uri}
onChangeImage={(uri) => onRemoveImage(uri)}
/>;
})}
<ImageInput onChangeImage={(uri) => onAddImage(uri)} />
</View>
I spent a while why my code is not working even after selecting an image from media library it is not getting displayed. Finally I figured out that in the first arrow function I accidentally used {} instead of (). The correct code is as below
<View style={styles.container}>
{imageUris.map((uri) => (
<ImageInput
imageUri={uri}
key={uri}
onChangeImage={(uri) => onRemoveImage(uri)}
/>
))}
<ImageInput onChangeImage={(uri) => onAddImage(uri)} />
</View>
So my question is can someone explain when is it appropriate to use a {} and () in an arrow function? I am very confused with the syntax.
Appreciate your help
Thank you.