Welcome to the React Show. Brought to you from Occupied Mi Walk Territory by me, your host Thomas, in Owl Creek, episode 60. Most common React questions on Stack Overflow answered. Plus some bonus background. Thank you for joining us. This one's gonna be uh a bit different. I'm actually uh getting ready to travel uh for a while. So I've been sort of cramming some some episodes in here, trying to get them recorded before I head out because um unfortunately the airlines these days are making it more difficult for me to fit the uh recording gear in with everything else, or at least, you know, within the constraints of expecting that uh they may lose, you know, the the checked baggage and and all that stuff. Um so yeah, uh not gonna be able to record probably for a bit unless I can find some other gear. Uh but yeah, uh figure, hey, let's let's try to get some in. And I'm actually really excited about this one. It's gonna be a little different. Um, we're just gonna take a look at well, sort of the inspiration will be taking a look on Stack Overflow, sort of the most common, frequently asked things about React. I mean, it's gonna be a lot of fun. I can tell you some some stories about uh times when I ran into that and how I'm sure I solved them in a worse way than all of you would. Or wait, do you come here for that? Anyways, it'll be fun. I'm pretty sure. I'm quite sure. It'll be a lot of fun. But yeah, that's also why we don't have a news section on this episode either, because when you record a bunch of episodes, you know, at the same time, essentially, and um, you know, it's not like a lot of news passes in between. Uh, but yeah, hopefully we'll have a lot of news coming up in the one after this. Of course, what I'm sure is not news to anyone listening to this, is that uh Ustate and uh family is very confusing, especially when you first get started. And that is definitely uh the recurring theme at the top of the Stack Overflow list is you know, why does Ustate not like why can't I see that change immediately? Like once I call UState, why don't I I just see the result of that use state? Or, you know, people being confused about like, hey, I have this like set timeout, why isn't it reading my updated state change value? All sorts of questions like that. And I think this is great in the sense that I'm I'm glad we we could talk about it now. It's definitely one of the more challenging parts about learning React for sure. So if you're just learning and you're getting into this and it's confusing or you see some weird results, definitely uh yeah, don't feel like you're alone because you're definitely not. And before we get into the React part, I just want to say that like this. So this reminds me of some other like non-react state issues I've had, and just the fact that state in programming is I don't know if I guess the most difficult part, or like, yeah, I guess making the right abstraction is the difficult part, but that is based on your state changes that will be happening. And so those in conjunction are definitely the most difficult part about programming. And React takes that to the next level, you know, compared to how a lot of people have learned their programming. Um, but yeah, just as an example, like state, like and and it's changing and what it might be is is always the difficult part when you're trying to, you know, get your program functioning. Like I remember one time I was working on, I was trying to learn like more low-level programming. And so I had this Raspberry Pi, and I would, yeah, I didn't have any, I wasn't running it on my software on top of anything. It was like pure assembly. My goal was basically to write a bootloader for it so I could learn how bootloaders work. And if you don't know about bootloader, basically it's just a piece of like assembly code that loads the actual, you know, operating system that your normal code normally runs in. And so this bootloader has no ecosystem around it, nothing around it. And the biggest thing is no debugger. And at this stage, you don't have if you're writing your own, of course, you don't even have any like like display output. So you can't like plug it into a display and easily, or or if you do, you're you're debugging the display output. I think that might have been what I was doing in this case. I don't know. I couldn't like plug it into a screen to like log out what was going on, you know? So it's like, okay, I know it's not working right because it's not doing, like, it's not loading what I thought it was loading, and I I forget what I was looking for, but I'm like, it's not working right, and I can't like I have no networking, I have no display. But but what I did have was one LED on the board. And so I figured out how to turn that LED on or off. And then I had the a bunch of like hard-coded, you know, like like things I could copy and paste to like flash that light a certain number of times. So that was that was my way of trying to debug the the state. And it did work, but oh boy, is that tedious? It's like, all right, so this variable might be this. If it's this, then flash it this many times. But okay, let me flash this to an SD card, plug it in, boot it up. Oh, wait, why didn't it flash? Wait, what? That doesn't make sense. I mean, you know how it goes. You've done some programming before, right? Like it's just you're like, I don't get it. Why is it doing this? You know, you get a little frustrated, maybe. But yeah, anyways, that's my little short side story on state and programming. And we can get back to these questions on Stack Overflow. And so use state or set state, I guess, specifically in React is confusing, I think, for actually two reasons. So, number one, it's asynchronous, which just means that you know, once you call set state, you're not gonna see the updated value of that state until the next render, which it can be hard for that to sort of get into your brain when you're just getting started, because you want to write your program like, you know, uh variable x equals this now, x plus this equals this. Like you want to have this like natural flow to it. And that's just not the way React works if you're using your component state like that. But the other part is the state is closed over, and so that's like a fancy computer science-y term to essentially mean that the state that you see, you know, once your component starts rendering, is forever gonna be the state that everything that executes in that component sees. So if you have a set timeout that references a use state variable, it's going to actually refer to the value that that state was in once your component started rendering. Like even if time passed by and you set the state a few times in between before your set timeout, you know, triggers, it doesn't matter. The way that this works is it just looks for, hey, what was the value when this component was rendered? That's a way to think of it. You can look up the I'm not gonna try to teach closures at the moment, but uh, if you're interested, you can look up like closures and and being closed over and how that what that actually means in a technical sense. But the practical sense is just that, and in fact, I think this actually makes it kind of easier to program in a sense, because all you have to do is be like, oh, my state and my props, like all this stuff, it is what it is at the start of rendering, it's not gonna change for anything else that runs here. It is a nice simple model, and actually, I I really like it because it makes your render more predictable. This sounds weird because you're like, wait, how is that more predictable? Now, when I'm changing state, like I don't know when is this state change gonna take place? That's the thing about React, that's not how it's been designed for you to approach it. You're not supposed to be like, oh, calculating when is this render gonna show my value? You're just supposed to be like, okay, given the state in the props, what is the output? And React should be able to, you know, pass in that same state and props and get the same output, you know, every time. That's the way that React is designed. And so you might call, like theoretically, I don't think this is really what is currently happening, but the way React is designed is theoretically you could call set state inside your component, and React could render that component like 20 more times before that change state value is the value that it uses for a render. Like that's the way React is designed to like that abstraction, that's the way to think about it. It's like, hey, I don't know when my changes are gonna be reflected in this component, but it doesn't matter. If you give me the same input, I'm gonna give you the same output no matter how many times you ask for it. So I like that because to me, it makes it predictable. All you need to do is know what the incoming state and props are, and you know what your component is gonna render as. But I think this is really difficult for people coming from a more like imperative model where you modify a variable and you immediately see that change reflected. That's sort of like the way a lot of us have been taught like how programming works. And that is a way that programming can work and it's very popular, but that also has a lot of downsides because once you start doing that, you can no longer just look at what the state and the props are when your component starts rendering and predict what the output's gonna be. And that has a lot of side effects and complications that we have to deal with when we are working within that model. And so I actually find the React model to function better, like you produce better results with the same amount of code as you would in a different model. Now, I think the interface with like set state and new state is weird. You know, I'm not gonna deny that. It is a bit weird. The way that this would like sort of normally work, and the way that I like to make it work when I have the the opportunity, is more like just a regular having a regular pure function that that takes a number of arguments and given those arguments gives you your output, and there's no internal state. And I think that's where it gets really weird is React is doing this sort of like pure functional programming style while having something that seems like internal state, and that's confusing. So I think in that sense, their implementation is sort of the source of the confusion, even if the end result, I think, is in a lot of ways better than a lot of the alternatives I've seen. I think the yeah, this interface is weird. And and it is uh, and I guess when I'm saying like a better, you know, way of doing things, I think it really sort of decouples our code, our like application code from the engine's code in a better way than how a lot of systems do it. Because this model where React can just keep track of the state and props for a component and pass it in and expect to get the same output and be able to call that as many times as it wants. Um, that means the engine, you know, React itself can evolve and change to take advantage of new developments in, you know, the browser and whatever environment it's running in, or even to custom tailor the implementation to the environment it's running on, you know, like maybe in React Native, it's able to run in a different way that's more efficient for that platform. And it's able to do that because of this model. And it's actually like uh I think a pretty powerful model, but it definitely their interface is different than what people are used to, and it's a little bit weird. So yeah, once again, if you get into this and and you get confused, I think that makes sense. Just it might be helpful to remember like all that really matters is given the same, you know, state values and the same props, I need to return the same output. And you know, when that state changes shouldn't matter. That's just the way that you have to think of approaching it. Like, that's the way the system works. So the next question is about using unique keys when you're working with arrays. I also notice this is confusing to um people, you know, just getting into React, which is probably why, again, it's so popular on Stack Overflow. But why is it? Why do you need to set you know key equal to some unique value for every element that's rendered in a loop? The answer can be summed up best in that uh React uh uses this sort of heuristic algorithm when it's rendering to detect when a DOM component on the screen or whatever platform you're using needs to be updated to reflect the state of the program. And it would be expensive for it to, you know, sort of automatically, magically do this for you. So they're sort of shoving this problem down the line onto us programmers and being like, yeah, our performance kind of sucks in this area, and it just that's the way it's gonna be. So the way that we're gonna get around that is we're gonna force you to give us this unique key so we can do our stuff uh with um less performance issues. That's really it. Of course, this is weird and confusing, uh, and it always is when your abstraction is leaking into other places. That's not good design. It makes sense why they did this. It's kind of probably the best. Uh I don't know, maybe, maybe not the best. I don't know, the best uh simple solution at least for resolving their internal performance bottlenecks. But yeah, if just a reminder, if you're new, you know, make sure your key is unique and also make sure it's stable. This is something that doesn't get talked about as much, but it's really important. So that means like when you're uh like let's say you have an array of JSON objects that you're getting back from the server and you want to render it into a list on the screen or whatever, right? Or some divs or whatever. The JSX that you're outputting in that loop, the key value for each like um element in that JSON array should always match up. So, like let's say you have three items, you know, item one, item two, and item three. The key for item one should always be the same. So even if the server is like returning things in a different order and at different times, you know, those keys should always be the same. That's what it means that they should be stable or or static. This is super, super important. In fact, this is like required. What I saw all the time when I first was learning, and I didn't realize why we were using the key prop is what I saw was people were just taking like the counter for a loop and using that as the key. And so it's like, oh, I have a for loop, and I could, you know, I'll take the value of i or whatever your index, you know, variable, your counter variable is, and that's my key. And I saw that all over and I didn't think anything of it. And I was just like, yeah, oh, okay, that's what you do. And then I was like, but that's weird. Why would you do that? Like that that should be something that React could calculate then. Like it just takes the result and assigns the key based on the order, you know, and of course I look into it and it's like, oh, that is not only not the right way to do it, that defeats the entire purpose. Like React is, you know, using this to essentially match up your output to what it puts on the screen. And so if you're not using the same key for the same item every time it renders, it's gonna be redrawing all of that stuff on the screen every single render. That's absolutely not what we want, you know? Like you got a thousand items in a list, you do not want them to be, you know, you don't want that DOM element or whatever to be reset up and recreated every single time it renders. So it's super important that it's both unique and stable. Don't have that key change. You got to figure out a way to make it work. You might be like, oh, I don't know what to do. I don't get a key or whatever. Maybe you make a key by combining different fields from the data, or maybe the server can start passing you a key or whatever it is. You need a stable key. If you don't have that, you're always gonna be running into issues that you basically can't solve. Yes, this next one is you know, my cup of tea. How to fix missing dependency warning when using use effect. Yeah, so you'll see this warning if you've ever used use effect, probably. It's like, oh, you're missing whatever, whatever in the dependency array. And you're like, but I don't want it to be in the dependency array because my use effect should only execute when this variable changes, but not when this variable changes. Well, I got news for you. You're using it wrong. That's not what it was designed for. Sorry, it's okay, it's okay, it's okay. Uh it's like everyone uses it wrong. Uh, but that's where that wording comes from. Basically, this is again another leaky performance abstraction from the React team. And uh, I really, I really wish they the this the reason why you would ever use your the dependency array for what React intended it to be used for, which was a performance optimization, is incredibly rare. I have done like pretty extensive testing and profiling around this. Um, anyways, the the reason why React created this dependency array in the first place was essentially when you have something that's rendering many, many, many, many times very quickly. And building up this list of effects to run after every render was causing a bit of a performance bottleneck. But the thing to understand is that this is only an issue at massive amounts of re-renders very quickly, and the performance difference is very slight. So, what I mean is what you could do instead of ever using this dependency array, and this is how it seems like React intended use effect in family to be used, um, is you put an if statement at the very beginning of your use effect that basically checks to see if the body of the use effect should actually run. So you could say if previous value of something equals the current value, you know, or does not equal, then I want to run my effect. Like if the state has changed, let's rerun my effect. But otherwise, I don't want to rerun this code. That's usually how people are using the dependency array. I'm gonna put something in this dependency array to make it so that my effect only runs when this value has changed. That was not the intention of the dependency array. That's not like I mean, technically that's what it is for, but in a in a different sense. Essentially, what you're supposed to do is put every, you know, for we'll use the common vernacular, every variable into that dependency array that gets used inside the use effect. So this could also be functions that get passed in, you know, things coming from use state or wherever. Like it doesn't matter if it's a value that could theoretically change in your program and needs to be in there if it's referenced inside the use effect. And this means even like, and this is where a lot of people, you know, will disagree with me is like they'll be like, well, I know that my function, the definition of my function is not gonna change. I don't need to put that in the list, right? And technically, from the way React designed it, Yeah, you're supposed to put it in the list. And if you don't, you're gonna get a warning. Um, but people will say, but I know it's not gonna change, I'm not changing it. Nothing in my code changes the definition of this, you know, variable. So it's fine to omit it, right? And, you know, yes, in that case, when your program is running, yes, you could omit it, but I would counter that and say, can you predict what people in the future are gonna do with your program? You know, maybe that that um function is being passed from somewhere else, or somebody eventually moves it to be passed from somewhere else, and they don't realize that they can't change its definition while the program is running. And they might think, oh, this would be really convenient if sometimes it has this definition, sometimes it doesn't, you know. So my point is just that if you don't follow that warning and put everything in there, you're opening yourself up for future bugs. And so this is why I always tell people just don't use that dependency array unless you actually have a performance bottleneck. And you've proven that just the mere fact of calling use effect, not running the code inside of it necessarily, but just calling it is a performance bottleneck. That's the only time that you really ever need to use it. And I have never ever, I've done a lot of React programming at this point. I've never actually found a case where I needed to do that, like literally ever. I mean, it just isn't useful. I don't use it, I do not put things in that dependency array. There's no point in it. I do always create a uh another hook I call use conditional effect that mimics the behavior that people are trying to get out of putting things in the dependency array. And this hook allows you to only specify the things you're expecting could change, and then you know, only runs the body of the you know hook when that state changes. Internally, that hook does things the right way by creating an if statement that checks, you know, if if the state, if the you know, specified state changes, and that effect still runs for every render. Just the body of the user's code only runs if things change. So that's the proper way to do it. And that will future-proof you to changes that React makes or you know, changes that people make to your code base that you're not expecting. And in fact, React has even said in the future, we may ignore the dependency array and auto-generate it for every effect. So they will analyze the code inside of the use effect and figure out what needs to go into that array. That's the optimal situation. That's hopefully they do that. Um, but wow, that's gonna break a lot of people's code. So yeah, this is um, I don't know, we've had like at least two episodes on this now. Um, so if you want to learn more, you know, you could check out some of our past episodes, do some of your own research. Um, but yeah, that's okay. I I I I would say more, but yeah, this we'll we'll leave it at this for now. Um, but I get it, it's confusing, and even probably what I just said might have been confusing. Uh and I get why this is a very popular topic on Stack Overflow. So, like, if you're struggling with it, I'm not saying this like, you know, to make you feel bad or anything, because I've been there, I've done it, I I did this for a while before I understood how it was used. So I wouldn't feel bad. And you know, you may you may uh run into people who disagree with this opinion or or whatever, which is fine. Um, but they're wrong. Um, just you know, facts are facts. Just kidding. No, it's all good. Um, we'll we'll look at the next one though. Call child method from parent. That's the title of this post. Essentially, it's uh asking, like, hey, I I want to call a method that's defined on a child from the parent, but it's not working right. It's is you know, and this is actually very common again, especially for people just learning React. And that is not understanding the flow of state through React, uh or you know, the way it executes. Um React is purely top-down, you know, like you have your highest level component and that renders other components, but it is not designed in any way for those top-level components to manipulate things directly in the child components. The way it's designed to work is you pass your props in or you know, your state via like a context or something. But you you can't, you're not, it's not designed to manipulate the child, you know, sort of directly other than that way. Things flow in that direction that as a tree from the top to the bottom. And this also takes some getting used to if you haven't worked in a system like this before. I think it also can be very annoying. I I think there could have been some other ways to have designed it, but hey, it is technically very simple. Um, so if you ever, you know, getting confused by this or you ever want to do something like this, I have done, I have run into this. And, you know, usually I mean you can always reframe it in terms of passing things down via props. And the way you would often do this is by passing like callback functions or something down through the tree. So if, for example, your parent component is the thing that actually maintains the state, but you want to have a button inside the child component that when it gets clicked, it sets the state in the parent component. You pass a function down that references the value that's being set at the parent level. So it's a different way of thinking about it, and it can be kind of it can get quite cumbersome if um what you do is put all this a lot, a common pattern is to end up with a lot of your state really high up in the tree because it's shared between a bunch of components, like child components, right? And so you're passing these callbacks down way deep into the tree all the time to update your state. It's a very common situation to end up in in React. It's also very cumbersome, but that's the way it works. Uh, what a lot of people do to improve that situation or to simplify it is to use a context. And they might use a context indirectly, like via React query or you know, some other library that's maintaining state, it's going to be internally using a context that makes it available to you know child components without having to pass it through all the props. So that can sort of help alleviate the situation. But the you know, sort of foundation here is that the way React works is things flow from top to bottom. They don't go from bottom to top. You don't try to mess with that. You're not gonna end up in a good place, I promise you. There's a way to do it where you don't need to do that, and it's gonna end up being better for you. Um, but I totally get the sort of confusion around this because it's just not the way that a lot of us are used to things working when coming from other platforms, other languages, you know, our sort of traditional, you know, programming, you know, background maybe hasn't exposed us to this method of writing code. I'll be honest, I I used to do this a lot in the in the sense that you used to do what? Um used to have this pattern where the parent contains all the state and you're like passing it down just via props, which is very clean and simple. It gets really, really tough to maintain. I in like not that you're ending up with like tons of bugs per se, um, as long as you're using like your prop types to you know make sure that required things are being passed in. You're not like moving things around and getting, you know, null passed in when you're expecting a function that you could call. As long as you're not doing that, it it does work, but it's just so cumbersome. And I I I I've worked at companies and I have my own projects where, especially when hooks had just come out, that's what I was doing. And yeah, now I it's I think it's kind of a hack, to be honest. Uh, it's not really it's definitely a hack, but I don't know, React provides it. And like I mentioned, that's context. Um, I usually use it um indirectly via query caching libraries like React Query. Um, because that's usually where the interface of your data is. Uh ultimately, there are actually I do have some applications where that's not true, and you can you know create your own context and use that directly. But yeah, in both cases, uh it can have its own issues, caching and sort of a global state. You know, people will preach against that, and I think sometimes for good reason. Um, but in React, it gets very cumbersome if you don't use something like that in a larger application. And yeah, it can get confusing and frustrating, and like, oh, I need to pass this function down through like 18 child components. Like, nobody wants to do that. Oh, this one's a fun one. Uh yeah, we'll switch to something uh less heavy. Uh, and that is uh, why in React do component names have to begin with capital letters? Uh so this is something that often again throws off new people. In fact, I was just working with someone like a couple of weeks ago, and we're you know, doing like a screen share while they were while we're like coding together, and they were you know typing out their component, and they're pretty new to React, but they're like a veteran programmer, like they they know their stuff, but they're still pretty new to React. And they typed out their component name, and the first letter was lowercase, which if you've done JavaScript, that's makes perfect sense. That's what you do. You just don't even think about it. That's just the convention we all use, right? And so they did that, and I was like, you know, that that probably won't work right. And they were like, really? I'm like, yeah, and so why is that? And that's that's the Stack Overflow question as well. And I thought it was interesting. So when when looking at this, uh, the uh history of it is actually that React in you know, JSX technically needs a way to know when something is a React component and when something is, you know, a DOM element, you know, so like div versus your custom React component. It has to be able to tell those apart. That there has to be some way for it to do that. Um, and you know, you might be thinking, like, oh, why can't it just like read my code and see what I've defined versus what I haven't or whatever? Um, this is actually getting compiled really before that process has taken place. So, like your JSX, it's a compiler that runs before your code actually gets run. So it's not, I mean, yes, they could still do it by analyzing your code. I don't know. They haven't chosen to, probably for complicated reasons, whatever. So the situation that we're left in is it needs an easy way to tell that distinction between a React component and you know, like a DOM element or you know, whatever the native element is to the platform you're using React on. And so originally React used a whitelist of common element names like div, which sounds ridiculous to me, but hey, I guess maybe, maybe you know you gotta do something. Uh and the in and they did change it for yeah, it was ridiculous. And the reason is is because uh you can define your own custom DOM elements. Uh, you you know, maintaining that list would be a pain. You know, anytime a browser or something supports a new element name, you got to add it to the whitelist, you gotta deploy it, people gotta use your latest version of that before they can even use that tag in their code. That's really annoying. So, what they decided to do is just create a rule that React components start with an uppercase letter or contain a dot, which is actually interesting. I didn't I didn't know about that part, but yeah, so that's really all it comes down to is the compiler is like, oh, hey, this is uppercase, it must be a React component. Oh, this is lowercase, it isn't a React component. It's a very interesting uh thing. Uh I don't know what else to say other than it's interesting. Um, and that's uh the reason for it. So, how do you perform debounce in React? So if you're uh not familiar with what that means, essentially think of like a component with a search box or text field or whatever that you type something into it and it hits an API and shows like sort of a searched filtered result, you know, based on what the user typed. A naive implementation of this would be I type a letter, I send a request to the server, I display the results. But what if the user is typing faster than you get results back from the server? Uh, you're gonna be firing off a bunch of requests that are pointless because the user's already searched something more specific and you're gonna have to fire off a new request and wait for that data to come in. And you may run into situations where the data comes in in different order and whatever. And so a debounce or debounce, I don't know, is essentially where you wait a little bit after the user has typed something before firing off that request. And if they have typed something else since then, you just cancel firing off that request. And this gives you a lot more performant search input system. It'll work way, way better. If you don't do this, you'll uh you can easily have performance issues. It's like re-rendering all the time while the user's trying to type. It's a terrible experience. And what I think is really interesting is the solution on Stack Overflow is very complicated. But uh all the solutions are very complicated. This is one of the most difficult things to do in React, like in a clean, simple way. It is just not made for it. But the great news is that very soon, theoretically, React is supposed to make this way, way better. Um, the React 18 release included like foundational support to do this in a much cleaner, better way. And I think they I can't remember, but I think they even might already have like a alpha API you can use for this. Either way, this should be improving dramatically, uh, hopefully soon. But in the meantime, I uh I mean, I guess if you need to do this, do your research. Hopefully, there's a library that works for you or something, because it turns out to be a lot more nuanced than you might think. And it's easy to make mistakes when implementing this. So I would definitely recommend if you run into the situation where you need to do this, try to find a solution that's already gonna work. Yeah, it's it's not a fun thing, and uh just the architecture of React as it stands now, it doesn't make this easy. Uh, but yes, you know, there is uh uh uh the sun is rising on this this issue. Next question, which I'm looking forward to talking about, is uh my React component is rendering twice because of strict mode. Yeah, so you might notice this if you run your uh code in strict mode. Um, if you don't run it in strict mode, I recommend doing that. Um, and this is one of the reasons why. So, why does your component render twice? This is actually just something that will happen in development, but not production mode. And the reason for it is React is essentially trying to get us ready for the future and saying, Hey, programmers, we made this system that is just supposed to be very like pure and functional, where you know, given state and props, we always return the same output. It's very simple. Like, why aren't you guys doing that? Why do you have these use effects that are messing up the system? You know, that's essentially what React is saying is hey, in the future, you know, we are definitely going to be, you know, rendering your component in sort of unexpected times, you know, maybe more than once with the same input. And the reason for this is because they're working on APIs that will allow them to start and stop and resume and suspend the rendering of a component. So they might start rendering a component or they might finish rendering it, then they'll render another one, then they'll come back and re-render the same one that they did earlier, or you know, only make it part way through and then have to come back and do it again. And this is to improve performance and concurrency mode, etc. But it's the way React is supposed to work. But people have been sort of, you know, React hasn't worked this way before it has just been like, hey, I only, you know, am rendering for a user-specific reason, you know, like a state has changed or whatever, then I'm I'm gonna re-render, or props have changed, then I'm gonna re-render, or the parent has changed, then I'm gonna re-render. All things that you can trace back to some sort of interaction. In the future, this is not the only way it's gonna work. Um, your component, you just have to program it for the fact that it might get re-rendered with the same input multiple times. You cannot depend on it only being once, you know, based on a some sort of user interaction or system interaction or whatever, which is the way a lot of people have written their React programs. And this is interesting to me because, like, I think conceptually, for me, this is how I've always approached React, but I think that's more because I have like a much more extensive, you know, functional programming background compared to a lot of React programmers. And so that's natural for me to think in that way. It's not so natural to other people. And the system in React should be, you know, designed in a way that it's resilient to people not understanding that it shouldn't silently do weird things. And in this case, I think it's kind of a failing of the design, although I don't actually have any ideas on how you do it better. But the fact is, um, yeah, that's how React is intended to work. And so, yeah, being rendered twice or three times or whatever, that's A-OK in the React book, and we need to be prepared for that. I think for me, like React in general, I have found it just sort of naturally fits with my way of thinking better than uh it seems like a lot of people who have come from, you know, maybe just pure JavaScript or PHP or a lot of other common backgrounds. And that is just because I really, really got into sort of pure functional programming long ago. And I've I've studied a lot of systems and worked on a lot of systems like this, and those fit better with the React model than the way a lot of people uh or a lot what a lot of people are used to coming from those systems. So, like, you know, if you've listened to me long enough, you'll know that I I really love Lisp, which actually isn't something that's purely functional, even if maybe you learned scheme in college and it felt like it or something. But I like to take advantage of that. It's not something where I'm like religious about it, like, oh, you know, I only ever use this. Although I have been thinking about it. Anyways, uh, that's topic for another day. I've been doing some research on that, but uh yeah, so I have found that as purely functional as you can make your code, which React can often do, uh, depending on how you do your use effects and stuff, the easier it is to reason about the code and the more predictable it will be, and just the generally the higher quality it will be. This has been my experience. If you have a system with really complicated state that changes in complicated ways, it's really, really, really hard for at least my little human brain to wrap itself around it and you know, understand all the different possible states that it can be in. And you have to be able to do that as a programmer to write a robust, reliable, maintainable program. And so to me, it's just very clean and straightforward. Like, oh, I pass in some data, and if the data that I'm passing in is the same, I'm always going to get the same output. It just feels a lot easier to reason about. And so I, you know, I've spent many years uh working in uh Lisp and other languages that allow me to program in that fashion. And so when I came to pick up React, it was like, oh, this is a little bit of a weird interface for it, but like I totally get what they're doing, it all just sort of makes sense. It it fits with that paradigm. So, anyways, yeah, that's uh I I like I like it. Hey, you know, um, if you haven't done much of that, uh definitely recommend, you know, if you get bored someday, just like mess around, like how pure can you make things? And this is a direction I've been uh contemplating lately, and you know, I'm not the only one, but like definitely a fun exercise to go into. And I'm not sure if this is as fun, but we're we're gonna do it anyways, and that is wrapping up this episode. So thank you for joining us uh once again. I hope you have a great rest of your day. This episode was produced by Thomas and edited by Dougie, the podcast editor.