1. Summary
Implement a useConfig hook for functional components, allowing developers to manage reactive state within their "render" functions in a React-like fashion.
2. Rationale
This hook provides a simplified entry point for developers familiar with useState from other frameworks. It leverages Neo.mjs's Tier 1 reactivity (Neo.core.Config) for state management without requiring class-based config definitions, making it ideal for the "beginner mode" functional component experience.
3. Scope & Implementation Plan
- Create File: Create
src/functional/useConfig.mjs.
- Implement
useConfig: The hook will return a [value, setter] tuple. The setter will update an internal Neo.core.Config instance.
- Lifecycle Management: Ensure the
Neo.core.Config instance is properly managed (created, updated, destroyed) in relation to the functional component's lifecycle. This will likely involve associating the core.Config instance with the Neo.functional.component.Base instance that is executing the "render" function.
4. Example Usage
import { useConfig } from 'neo/functional/useConfig.mjs';
import { defineComponent } from 'neo/functional/defineComponent.mjs';
const MyCounter = defineComponent({
className: 'MyApp.MyCounter',
createVdom: () => {
const [count, setCount] = useConfig(0);
return {
tag: 'button',
text: `Count: ${count}`,
listeners: {
click: () => setCount(count + 1)
}
};
}
});
5. Definition of Done
Neo.functional.useConfig hook is implemented and tested.
- It correctly creates and manages reactive state via
Neo.core.Config.
- Changes to the state trigger re-execution of the component's render function (via
Effect).
1. Summary
Implement a
useConfighook for functional components, allowing developers to manage reactive state within their "render" functions in a React-like fashion.2. Rationale
This hook provides a simplified entry point for developers familiar with
useStatefrom other frameworks. It leverages Neo.mjs's Tier 1 reactivity (Neo.core.Config) for state management without requiring class-based config definitions, making it ideal for the "beginner mode" functional component experience.3. Scope & Implementation Plan
src/functional/useConfig.mjs.useConfig: The hook will return a[value, setter]tuple. Thesetterwill update an internalNeo.core.Configinstance.Neo.core.Configinstance is properly managed (created, updated, destroyed) in relation to the functional component's lifecycle. This will likely involve associating thecore.Configinstance with theNeo.functional.component.Baseinstance that is executing the "render" function.4. Example Usage
import { useConfig } from 'neo/functional/useConfig.mjs'; import { defineComponent } from 'neo/functional/defineComponent.mjs'; // Assuming this exists const MyCounter = defineComponent({ className: 'MyApp.MyCounter', createVdom: () => { const [count, setCount] = useConfig(0); return { tag: 'button', text: `Count: ${count}`, listeners: { click: () => setCount(count + 1) } }; } });5. Definition of Done
Neo.functional.useConfighook is implemented and tested.Neo.core.Config.Effect).