
If you've got any questions feel free to DM on Twitter @reillyjodonnell
Search for a command to run...

If you've got any questions feel free to DM on Twitter @reillyjodonnell
No comments yet. Be the first to comment.
Someone shared this image above. At first glance, I wasn’t sure about the perf implications — so let’s break it down from first principles :D Let’s deconstruct this monster Here’s the code: // Function to flatten React Context Providers. const flatte...

Intro Hello it’s me from the future! I originally was going to go over file based routing but pivoted to going over important SSR concepts with React / how Bun makes it easy. It’s full of struggles with hydration (mismatches), React entry points, and...

history? Serverless is EVERYWHERE and for good reason: nearly infinite scalability, physically closer to users, and pay-for-what-you-use pricing. But not without tradeoffs — vendor lock-in, (potentially) higher costs, and the infamous cold-starts. cf...

Powered by bash and AppleScript!

Sockets can only transmit binary (text.) Imagine we have this data const message = {id: '123', name: 'Reilly', message: 'Hey'} Here's the problem: we want to send this data to the ui but we have hundreds of useEffects spread throughout the codebase....

The React docs defines props as
When React sees an element representing a user-defined component, it passes JSX attributes and children to this component as a single object. We call this object “props”.
They also use the following code snippet as an example
const element = <Welcome name="Sara" />;
Here we see that the "user-defined component" is Welcome and the object, or props, is called name with the value of Sara.
Let's see another example below ⬇️
To start we have a functional component as shown below:
function MyComponent() {
return (
<div >
</div>
);
}
As we can see this component doesn't do anything, yet!
Let's add some magic 🪄 by passing the component properties, or props.
Below we create a variable called message and assign it a string of text.
Now the cool part 😎
Attach an object with any name (we use "secret" here) to the component as shown below
var message = "Props is now showing! Awesome!";
<MyComponent secret={message} />
Now notice here, unlike the example from the React docs above, message is surrounded by curly braces. This is because the value is JavaScript and must be enclosed in curly braces per JSX rules.
Similarly we could have just done
<MyComponent secret="Props is now showing! Awesome!" />
You've just successfully passed props! 🎉
Now we need to access it within the component, MyComponent.
To access the props we need to pass an optional parameter to the functional component
This parameter can be any name you want - but it's HIGHLY advised to use the word props
function MyComponent(props) {
return (
<div >
</div>
);
}
Great - now how do we access it?
if we console.log(props) we get:
-> {secret: "Props is now showing! Awesome!"}
Just as we expected props is in the form of an object. To access it use the dot notation (props.secret)
function MyComponent(props) {
return (
<div >
{props.secret}
</div>
);
}
Notice again that we didn't say props.secret - we used {props.secret}
Reminder in case you missed it earlier: this is because in React we use JSX and by using curly braces we are saying we want to display JavaScript code.
Props is read-only. Meaning when we access props in the component we are not allowed to assign props a new value within the component.
If we want to assign props a new value it MUST be changed outside the component.
Now we have successfully passed props and accessed it in the component! 🥳
In the next article we will look at another fundamental topic: State