From the course: Build with AI: Beyond Pair Programming with AI

Coaching the AI to use modern standards

From the course: Build with AI: Beyond Pair Programming with AI

Coaching the AI to use modern standards

- [Instructor] Once I've detected an old pattern amplified by the AI, I want to use the AI to change my code to use a newer pattern. And chances are it has the necessary patterns in its training data to do this. But we need to bias it towards a different way of doing things. In responsive images DSX, I have this JSX.Element that I want to get rid of. And to do that I'm going to highlight this entire component here and then go into my chat and say, JSX.Element is no longer recommended. Suggest alternatives. Let's see what the system says. So the plan is to replace JSX.Element with React.FC, but React.FC is also not recommended. So I'll say React.FC is also not recommended, suggest alternatives. And at this point it comes up with the right answer. Right now the replacement for JSX.Element is React.ReactElement. So let's see if it can refactor my code to get that to work. So down here we have the same responsive image, but instead of using JSX.Element, it's using React.ReactElement. So now that I have a suggestion with the correct code, I'll click on the insert, this will go scan through the file and see where the changes are. I get the recommended changes down here. I think it's only this piece, so I can accept that change. It also reinjected import react at the top and I don't want that. So I'll say no to that. And now we have an updated code. This is really all there is to it. Anytime you encounter old code, chances are the system actually has the ability to generate the new code, but you have to coach it to do this, you have to actively tell the AI what you did is old or wrong or deprecated or no longer in use, or I don't want to do this. And then have it suggest alternatives. And when it does, there is a chance it'll suggest another older way of doing things. So this is a good reminder that you need to be really on top of whatever you're doing to understand your code language or your framework so you know what is the current latest standard and you can get the AI to follow that standard.

Contents