R
R
Roman Alexandrovich2017-02-21 23:01:00
React
Roman Alexandrovich, 2017-02-21 23:01:00

Calling a method function outside a class (React js)?

Good evening. Faced with the urgent need to call a class method outside the class

const SortableItem = SortableElement(({value}) =>
    <li className="listStyle">
        {value.video.time !== 0 ?
         <Button bsStyle="primary" onClick={()=>{}}>-</Button> : null}      //сдесь необходим вызов функции deleteItem
    </li>);
class GroupPage extends Component {
    deleteItem(item){
        console.log('item',item)
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2017-02-22
@RomReed

It is always possible to call static methods outside the class. (a bit on your question on SO )

class GroupPage extends Component {
    static deleteItem(item){
        console.log('item',item)
    }
}
...
const SortableItem = SortableElement(({value}) =>
    <li className="listStyle">
        {value.video.time !== 0 ?
         <Button bsStyle="primary" onClick={()=> GroupPage.deleteItem()}>-</Button> : null}  
    </li>);

I
Ivan, 2017-02-22
@LiguidCool

Use ref 's.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question