LearnNewsExamplesServices
Frontmatter
id7012
titleCreate `Neo.functional.useConfig` Hook
stateClosed
labels
enhancement
assignees[]
createdAtJul 11, 2025, 4:05 AM
updatedAtJul 11, 2025, 12:39 PM
githubUrlhttps://github.com/neomjs/neo/issues/7012
authortobiu
commentsCount0
parentIssue6992
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 11, 2025, 12:39 PM

Create Neo.functional.useConfig Hook

Closed v10.0.0-beta.6 enhancement
tobiu
tobiu commented on Jul 11, 2025, 4:05 AM

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

  1. Create File: Create src/functional/useConfig.mjs.
  2. Implement useConfig: The hook will return a [value, setter] tuple. The setter will update an internal Neo.core.Config instance.
  3. 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'; // 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.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).
tobiu added parent issue #6992 on Jul 11, 2025, 4:05 AM
tobiu added the enhancement label on Jul 11, 2025, 4:05 AM
tobiu referenced in commit fc15419 - "Create Neo.functional.useConfig Hook #7012" on Jul 11, 2025, 12:39 PM
tobiu closed this issue on Jul 11, 2025, 12:39 PM