UNPKG

react-app-shell

Version:

react打包脚本和example, 这里的版本请忽略

38 lines (30 loc) 855 B
import {PureComponent} from 'react'; import PropTypes from 'prop-types'; import queryString from 'query-string'; import {localStore} from '../../utils'; class SetParamToCookie extends PureComponent { static propTypes = { paramKey: PropTypes.string // 参数 }; static defaultProps = { paramKey: 'rf' // rf参数是推荐人或渠道 }; componentDidMount() { this.addParamToCookie(); } /** * 根据rf参数, 添加到cookie里 */ addParamToCookie = () => { const {paramKey} = this.props; // 如果url参数存在 const urlParam = queryString.parse(window.location.search); if (urlParam[paramKey]) { localStore.set(paramKey, urlParam[paramKey]); } }; render() { return null; } } export default SetParamToCookie;