Skip to content

Commit

Permalink
feat(@tinacms/react-core): useCMSEvent makes subscribing to events ea…
Browse files Browse the repository at this point in the history
…sier
  • Loading branch information
ncphillips committed Oct 8, 2020
1 parent 3ab978c commit 2a276bf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@tinacms/react-core/src/index.ts
Expand Up @@ -21,4 +21,5 @@ export * from './use-form'
export * from './use-plugin'
export * from './use-subscribable'
export * from './use-watch-form-values'
export * from './use-cms-event'
export * from './with-plugin'
33 changes: 33 additions & 0 deletions packages/@tinacms/react-core/src/use-cms-event.ts
@@ -0,0 +1,33 @@
/**
Copyright 2019 Forestry.io Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import * as React from 'react'
import { Callback } from '@tinacms/core'
import { useCMS } from './use-cms'

export function useCMSEvent(
event: string | string[],
callback: Callback,
deps: React.DependencyList
) {
const cms = useCMS()

React.useEffect(function() {
return cms.events.subscribe(event, callback)
}, deps)
}

0 comments on commit 2a276bf

Please sign in to comment.