{
test: /\.s[ac]ss$/i,
use: [
{
loader: 'style-loader',
options: {
sourceMap: true,
},
},
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: {
exportLocalsConvention: 'camelCase',
},
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
parser: 'postcss-js',
},
execute: true,
},
},
],
},
async getCommentsChildren(kids: number[], id: number, children: IComment[]) {
const data: IComment[] = [];
if (kids === undefined) return;
for (const item of kids) {
const response = await api.get<IComment>(
`https://hacker-news.firebaseio.com/v0/item/${item}.json`
);
data.push(response);
}
const recursFunc = (comments: IComment[]) => {
if (!comments) return;
for (let i = 0; i < comments.length; i++) {
comments[i].children = data;
if (comments[i].kids.length) {
recursFunc(comments[i].children);
}
}
return comments;
};
runInAction(() => {
this.comments = recursFunc(children);
});
}
const RecursiveComponent: FC<IRecursiveProps> = observer(({ data, getChildren }) => {
if (!Array.isArray(data)) {
return null; // or any fallback component or message
}
return (
<div>
{data.map((parent: any) => {
return <Comment parent={parent} getChildren={getChildren} data={data} />;
})}
</div>
);
});
// appContext.js
import React from 'react';
export const AppContext = React.createContext({});
// App.js
import { AppContext } from './appContext';
function App() {
const [store, setStore] = useState(initialState); // начальное состояние Redux store
return (
<AppContext.Provider value={{ store, setStore }}>
<Routes>
<Route path='items' element={<Items />} />
</Routes>
</AppContext.Provider>
);
}
// Dashboard.js
import React, { useContext } from 'react';
import { useSearchParams } from 'react-router-dom';
import { AppContext } from '../appContext';
function Dashboard() {
const { store } = useContext(AppContext);
const [searchParams] = useSearchParams();
// получаем данные из текущего состояния Redux store
const items = store.items;
// обновляем данные в Redux store, если это необходимо
if (searchParams.get('update')) {
const newItems = await fetchItems(); // получаем новые данные
setStore(prevState => ({ ...prevState, items: newItems })); // обновляем состояние Redux store
}
return (
<div>
{items.map(item => (
<div key={item.id}>{item.name}</div>
))}
</div>
);
}