maomao-terminal 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,21 +81,25 @@ import { useEffect } from 'react';
|
|
|
81
81
|
import { useTerminalContext } from 'maomao-terminal';
|
|
82
82
|
|
|
83
83
|
const UserProfile = ({ userId }) => {
|
|
84
|
-
const {
|
|
84
|
+
const { registerDynamicCommands, unregisterDynamicCommands } = useTerminalContext();
|
|
85
85
|
|
|
86
86
|
useEffect(() => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
const commands = [
|
|
88
|
+
{
|
|
89
|
+
command: 'getUser',
|
|
90
|
+
response: async (args) => {
|
|
91
|
+
// You can clear data, fetch API, or log info
|
|
92
|
+
return `Current User ID: ${userId}`;
|
|
93
|
+
}
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
// Register a command specific to this component
|
|
98
|
+
registerDynamicCommands(commands);
|
|
95
99
|
|
|
96
100
|
// Cleanup when component unmounts
|
|
97
|
-
return () =>
|
|
98
|
-
}, [userId,
|
|
101
|
+
return () => unregisterDynamicCommands(commands);
|
|
102
|
+
}, [userId, registerDynamicCommands, unregisterDynamicCommands]);
|
|
99
103
|
|
|
100
104
|
return <div>User Profile Component</div>;
|
|
101
105
|
};
|