# Plugin onAction method does not have access to view or state

**URL:** <https://discuss.prosemirror.net/t/plugin-onaction-method-does-not-have-access-to-view-or-state/440>\
**Category:** Uncategorized\
**Created:** [October 11, 2016, 9:50am UTC](https://discuss.prosemirror.net/t/plugin-onaction-method-does-not-have-access-to-view-or-state/440 "2016-10-11T09:50:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kapouer](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/kapouer/32/227_2.png) [@kapouer](https://discuss.prosemirror.net/u/kapouer)\
**Post date:** [October 11, 2016, 9:50am UTC](https://discuss.prosemirror.net/t/plugin-onaction-method-does-not-have-access-to-view-or-state/440/1 "2016-10-11T09:50:10Z")

</div>

And it feels weird, considering all other props: [http://prosemirror.net/version/2016.09.21.html#view.EditorProps.onAction](http://prosemirror.net/version/2016.09.21.html#view.EditorProps.onAction) get “view” as the first parameter.

In my case, i try to port prosemirror 0.10 code where i had a plugin listening `selectionChange` events, so the new plugin declare a `onAction` prop and checks `action.type == "selection"`. In the previous version i used to get the view from plugin’s initialization, and it could have been possible to avoid that except for the above remark.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [October 11, 2016, 10:06am UTC](https://discuss.prosemirror.net/t/plugin-onaction-method-does-not-have-access-to-view-or-state/440/2 "2016-10-11T10:06:55Z")

</div>

Plugins are not allowed to expose an `onAction` method at all. Only the main props object can (and must) have that.

---

<div class="post-metadata">

**Author:** ![kapouer](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/kapouer/32/227_2.png) [@kapouer](https://discuss.prosemirror.net/u/kapouer)\
**Post date:** [October 11, 2016, 10:45am UTC](https://discuss.prosemirror.net/t/plugin-onaction-method-does-not-have-access-to-view-or-state/440/3 "2016-10-11T10:45:30Z")

</div>

I don’t get it, aren’t props passed as argument to `new Plugin({ props: { onAction: ...} })` ?

---

<div class="post-metadata">

**Author:** ![kapouer](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/kapouer/32/227_2.png) [@kapouer](https://discuss.prosemirror.net/u/kapouer)\
**Post date:** [October 11, 2016, 11:41am UTC](https://discuss.prosemirror.net/t/plugin-onaction-method-does-not-have-access-to-view-or-state/440/4 "2016-10-11T11:41:56Z")

</div>

Ok, so i’m supposed to use a StateField… it’s just that the plugin documentation is a bit misleading for rookies.

---

<div class="post-metadata">

**Author:** ![kapouer](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/kapouer/32/227_2.png) [@kapouer](https://discuss.prosemirror.net/u/kapouer)\
**Post date:** [October 11, 2016, 12:14pm UTC](https://discuss.prosemirror.net/t/plugin-onaction-method-does-not-have-access-to-view-or-state/440/5 "2016-10-11T12:14:55Z")

</div>

And i just noticed the

> Except for state and onAction, these may also be present on the props property of plugins.

line in the documentation. Maybe the plugins documentation should repeat that piece of information.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [October 13, 2016, 7:57pm UTC](https://discuss.prosemirror.net/t/plugin-onaction-method-does-not-have-access-to-view-or-state/440/6 "2016-10-13T19:57:52Z")

</div>

Added a note in the plugin docs in [this patch](https://github.com/ProseMirror/prosemirror-state/commit/a085ed43608b3ce3aecf846f18ac95a51abd597c)
