@mashincode

Как отрендерить такой компонент?

В общем пытаюсь отрендерить компонент стандартным способ через , но получаю ошибку
Line 338:  Expected an assignment or function call and instead saw an expression  no-unused-expressions

Search for the keywords to learn more about each error.


Вот мой код

class DragAndDropSidebar extends Component {
  
    constructor(props) {
        super(props)
        this.state = cloneDeep(chartSimple)
    }

    render = () => {
        const chart = this.state
        const stateActions = mapValues(actions, (any) =>
            (...args) => this.setState(...args))
        return (
            <Page>
                <Content>
                    <FlowChartWithState initialValue={chart} config={{
                        snapToGrid: true,
                    }} Components={{
                        NodeInner: NodeInnerCustom,

                    }} callbacks={stateActions}/>
                </Content>
                <Sidebar>
                    { chart.selected.type
                        ? <Message>
                            <div>Type: {chart.selected.type}</div>
                            <div>ID: {chart.selected.id}</div>
                            <br/>
                            {/*
                We can re-use the onDeleteKey action. This will delete whatever is selected.
                Otherwise, we have access to the state here so we can do whatever we want.
              */}
                            <button onClick={() => stateActions.onDeleteKey({})}>Delete</button>
                        </Message>
                        : <Message>Click on a Node, Port or Link</Message> }
                </Sidebar>
                <Sidebar>

                    <SidebarItem
                        type="type1"
                        ports={{
                            port1: {
                                id: 'port1',
                                type: 'right',
                                properties: {
                                    custom: 'property',
                                    value: "yes",
                                },
                            },
                        }}
                        properties={{
                            custom: 'property',
                        }}
                    />
                    <SidebarItem
                        type="type2"
                        ports={{
                            port1: {
                                id: 'port1',
                                type: 'right',
                                properties: {
                                    custom: 'property',
                                    value: "yes",
                                },
                            },
                        }}
                    />
                    <SidebarItem
                        type="type3"
                        ports={{
                            port1: {
                                id: 'port1',
                                type: 'left',
                                properties: {
                                    custom: 'property',
                                    value: "no",
                                },
                            },
                        }}
                    />
                    <SidebarItem
                        type="type4"
                        ports={{
                            port1: {
                                id: 'port1',
                                type: 'left',
                                properties: {
                                    custom: 'property',
                                    value: "no",
                                },
                            },
                        }}
                    />
                    <SidebarItem
                        type="type5"
                        ports={{
                            port1: {
                                id: 'port1',
                                type: 'left',
                                properties: {
                                    custom: 'property',
                                    value: "no",
                                },

                            },
                        }}
                    />
                    <SidebarItem
                        type="type6"
                        ports={{
                            port1: {
                                id: 'port1',
                                type: 'left',
                                properties: {
                                    custom: 'property',
                                    value: "no",
                                },
                            },
                            port2: {
                                id: 'port2',
                                type: 'right',
                                properties: {
                                    custom: 'property',
                                    value: "yes",
                                },
                            },
                        }}
                    />
                </Sidebar>
            </Page>
        )
    }
}

function App() {
  <DragAndDropSidebar/>
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
  • Вопрос задан
  • 65 просмотров
Решения вопроса 2
MrDecoy
@MrDecoy
Верставший фронтендер
Так как код Вы скинули не полный, то и дебажить сложнее. У Вас тут явно не 338 строк кода, на которой показывает ошибку, плюс непонятно откуда берущаяся переменная в cloneDeep.

Поэтому на глаз: renderопределить как метод, а не как переменную?
https://ru.reactjs.org/docs/components-and-props.html

И сделать return из App

то есть
// Не так
render = () => {
// code...
}

// А так
render() {
// code...
}

// И так
function App() {
  return <DragAndDropSidebar/>
}

// Или так:
const App = <DragAndDropSidebar/>
Ответ написан
Zhanna_K
@Zhanna_K
in progress
Вместо
function App() {
  <DragAndDropSidebar/>
}


Должно быть
function App() {
return (
  <DragAndDropSidebar/>
   )
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы