JavaScript React Basics (retired) Designing Data Flow Restructuring State

Jessica Graham
Jessica Graham
6,878 Points

When you're doing a return within the 'getDefaultProps' function, why does it uses curly braces {}

whereas in the 'render' function it uses brackets ()?

2 Answers

Alex Warner
PRO
Alex Warner
Pro Student 4,987 Points

My best guess is the value being returned by the getDefaultProps method (aka function) is a javascript object which is always enclosed in curly braces for example {myName: "Alex", myCity: "Los Angeles"}. The render method returns an html string which can be contained in parens ()

when you put things in (....) written like return (...), you're returning whatever is in there

meaning, if you can follow my poor writing,

you could write return {....} as return ( {.... } )

it just depends on what the specific function expects returned that will cause the minor differences in syntax!

In this specific example, the function for getDefaultProps is written to accept an object full of keys, the keys being the default properties you're getting

edit: also, those aren't brackets, they are paranthesis lols! Just sayin'. Brackets are what we write arrays with [....... ]