An example of GPTs being rubber-ducks that can reason ...
In an earlier toot, I mentioned that GPTs are rubber-ducks that can reason.
Design a preact component called "settings" that has two fields and a button: name and style. Name is a single line text field. Style is a multi-line text field. Button is "save". When it is displayed, it should load a token from the localstorage (stored with localforge) and call the backend api to fetch these details. When clicking save, it should send the details to backend api to save. If there are any errors it should display the error in red color and stay in the same screen. If there are no errors, it should goto home page.
It went about giving me this code:
class Settings extends Component {
state = {
name: '',
style: '',
error: null,
loading: true
};
componentDidMount() {
this.fetchSettings();
}
...
}
I read through the code before copying. I was wondering if I should use usestate
or this form of having component variables. So I asked:
I don't know preact. so this question could be stupid. should you use usestate to manage state or just assigning variables to state variable as you have mentioned in this last code block is ok?
Guess what, Claude responded with this:
Your question isn't stupid at all - it's a great one! The approach to managing state in Preact (and React) has evolved over time, and there are indeed different ways to handle it. Let me explain:
Class Components (what I showed): In the code I provided, I used a class component with this.state. This is an older but still valid way of managing state in Preact/React.Functional Components with Hooks (modern approach): The more modern and now preferred way is to use functional components with hooks, specifically useState.It reasons! It teaches. So it is not a dump portal from which I copy code (remember Stackoverflow?). Now I can understand the code I make.
#devnote #gptusage