Recent studies suggest that allowing individuals to choose their partners can help to maintain cooperation in human social networks; this behaviour can supplement behavioural reciprocity, whereby humans are influenced to cooperate by peer pressure. However, it is unknown how the rate of forming and breaking social ties affects our capacity to cooperate. Here we use a series of online experiments involving 1,529 unique participants embedded in 90 experimental networks, to show that there is a 'Goldilocks' effect of network dynamism on cooperation. When the rate of change in social ties is too low, subjects choose to have many ties, even if they attach to defectors. When the rate is too high, cooperators cannot detach from defectors as much as defectors re-attach and, hence, subjects resort to behavioural reciprocity and switch their behaviour to defection. Optimal levels of cooperation are achieved at intermediate levels of change in social ties.