This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
const SocketContext = React.createContext() | |
export default SocketContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React | |
import SocketContext from './socket-context' | |
import * as io from 'socket.io-client' | |
const socket = io() | |
const App = props => ( | |
<SocketContext.Provider value={socket}> | |
<YourChildComponent /> | |
</SocketContext.Provider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import SocketContext from './socket-context' | |
import axios from 'axios' | |
class YourDeeplyNestedComponent extends Component { | |
componentDidMount() { | |
axios.post('/api/messages', { | |
message: 'This is a new message' | |
}) | |
.then(response => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.equalHeight = function(options) { | |
var maxHeight = 0; | |
this.each(function(index) { | |
var height = $(this).height(); | |
if (height > maxHeight) { maxHeight = height }; | |
}); | |
return this.each(function(index) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Utils from '../utilities' | |
class PlanetsListTable extends Component { | |
componentDidMount() { | |
new Promise((resolve, reject) => { | |
Utils.getPlanets('https://swapi.co/api/planets', [], resolve, reject) | |
}) | |
.then(response => { | |
this.props.loadPlanetsSuccess(response) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import moment from 'moment'; | |
const originalDateString = '06/03/2019'; | |
const date = moment(originalDateString, 'DD/MM/YYYY'); | |
//-------------------------------------------------------------- | |
// Convert date string in DD/MM/YYYY format to YYYY-MM-DD format | |
//-------------------------------------------------------------- | |
const convertedDateString1 = date.format('YYYY-MM-DD'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Animated.useCode( | |
() => Node | Node[] | boolean | null | undefined, | |
[...dependencies] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyOpacityComponent = () => { | |
const [toggled, setToggled] = useState(false) | |
const opacity = useRef<Value<number>>(new Value(0)) | |
useCode(() => [set(opacity.current, runOpacityTimer())], []) | |
return ( | |
<Animated.View style={{ opacity: opacity.current }}> | |
<Text>Hello World</Text> | |
</Animated.View> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const UseCodeComponentMountExample = () => { | |
const value = useRef<Value<number>>(new Value(0)) | |
useCode(() => [debug('console log in useCode', value.current)], []) | |
return ( | |
<View>Example</View> | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const UseCodeInputNodeUpdatedExample = () => { | |
const [toggled, setToggled] = useState(false) | |
const destValue = useRef<Value<number>>(new Value(0)) | |
const opacity = useRef<Value<number>>(new Value(0)) | |
useCode(() => [debug('console log in useCode 1', destValue.current)], []) | |
useCode(() => [debug('console log in useCode 2', opacity.current)], []) | |
useEffect(() => { |
OlderNewer