-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undefined: Duplicate declaration "initLoading" #148
Comments
me too! how to fix |
instead of destructure statement here |
Thanks. I'll try it. |
Hello all, Thanks @ankitprahladsoni, I'm also trying to convert a react class component into a functional component and using your approach effectively eliminates that error message. Now I get a different error message I have no clue how to fix: You must pass a scope and parentPath unless traversing a Program/File. Instead of that you tried to traverse a Identifier node without passing scope and parentPath. Please find below the class I'm trying to transform:
And the data.js file is as below:
Regards. |
@mtchuenten I just tried moving the import React, { useState, useRef, useCallback } from 'react';
import DataGrid, { Column, Selection, Toolbar, Item } from 'devextreme-react/data-grid';
import SelectBox from 'devextreme-react/select-box';
import Button from 'devextreme-react/button';
import { employees } from './data.js';
const titles = ['All', 'Dr.', 'Mr.', 'Mrs.', 'Ms.'];
const App = (props) => {
const [prefix, setPrefix] = useState();
const [selectedEmployeeNames, setSelectedEmployeeNames] = useState();
const [selectedRowKeys, setSelectedRowKeys] = useState();
const selectionChangedBySelectBox = useRef();
const dataGrid = useRef();
const onSelectionChanged = useCallback(() => {
selectionChangedBySelectBox.current = false;
setPrefix(null);
setSelectedEmployeeNames(getEmployeeNames(selectedRowsData));
setSelectedRowKeys(selectedRowKeys);
});
const onClearButtonClicked = useCallback(() => {
props.instance.clearSelection();
});
const onSelectionFilterChanged = useCallback(() => {
selectionChangedBySelectBox.current = true;
const prefix = value;
if (prefix) {
const filteredEmployees =
prefix === 'All'
? employees
: employees.filter((employee) => employee.Prefix === prefix);
const selectedRowKeys = filteredEmployees.map((employee) => employee.ID);
setPrefix(prefix);
setSelectedRowKeys(selectedRowKeys);
setSelectedEmployeeNames(getEmployeeNames(filteredEmployees));
}
});
// commented out the below to avoid the undefined: Duplicate declaration error
// const {
// prefix, selectedRowKeys, selectedEmployeeNames,
// } = this.state;
return (
<div>
<DataGrid
id="grid-container"
dataSource={employees}
keyExpr="ID"
onSelectionChanged={onSelectionChanged}
ref={(ref) => {
dataGrid.current = ref;
}}
selectedRowKeys={selectedRowKeys}
showBorders
>
<Selection mode="multiple" />
<Column dataField="Prefix" caption="Title" width={70} />
<Column dataField="FirstName" />
<Column dataField="LastName" />
<Column dataField="Position" width={180} />
<Column dataField="BirthDate" dataType="date" width={125} />
<Column dataField="HireDate" dataType="date" width={125} />
<Toolbar>
<Item location="before">
<SelectBox
dataSource={titles}
onValueChanged={onSelectionFilterChanged}
placeholder="Select title"
width={150}
value={prefix}
/>
</Item>
<Item location="before">
<Button
disabled={!selectedRowKeys.length}
onClick={onClearButtonClicked}
text="Clear Selection"
/>
</Item>
</Toolbar>
</DataGrid>
<div className="selected-data">
<span className="caption">Selected Records:</span>{' '}
<span>{selectedEmployeeNames}</span>
</div>
</div>
);
};
function getEmployeeName(row) {
return `${row.FirstName} ${row.LastName}`;
}
function getEmployeeNames(selectedRowsData) {
return selectedRowsData.length
? selectedRowsData.map(getEmployeeName).join(', ')
: 'Nobody has been selected';
}
export default App; |
Thank you for pointing that out @ankitprahladsoni, it alllowed me to make some progress. I also moved the render method to the bottom of the class definition and glean could convert the class component into a functional component, but with an error, such that I'm not sure if the conversion process actually completed:
The component isn't rendered because react encountered an error during compilation:
I don't know if this error is related to the error reported by glean during component conversion. Please note that I use glean v5.2.2 and react v18.2.0, if that can be of any relevance. Regards. |
I've noticed it before and am unsure if it's a bug, but when functions are converted to |
Microsoft Windows 10 Pro, 10.0.19043 Build 19043
Visual Studio Code 1.62.0 (system setup)
glean v5.2.2
I attempted to refactor a class component into a functional component. At the end of the process glean presents an alert displaying the text:
undefined: Duplicate declaration "initLoading"
. You can see it in the following images.The component code (slightly modified from Ant Design documentation example Load More).
The text was updated successfully, but these errors were encountered: